Error 4605 after unprotecting document

A

Andy Smith

I am looking for a workaround to the following issue

http://support.microsoft.com/?id=275966

I have 70+ templates so would rather change the code

This is what we have
***********************************

'Get the document to be opened
goWord.Documents.Open Filename
If goWord.ActiveDocument.ProtectionType <>
wdNoProtection Then
goWord.ActiveDocument.Unprotect "Protected"
End If

'turn error handling off while we see if we can access
the page setup object in a particular way.
On Error Resume Next
'see if we can get at the page setup object this way
iTest = goWord.ActiveDocument.Sections
(1).Range.Paragraphs(1).Range.PageSetup
If Err.Number = 0 Then
With goWord.ActiveDocument.Sections
(1).Range.Paragraphs(1).Range.PageSetup
.FirstPageTray = FirstPageTray
.OtherPagesTray = SubsPagesTray
End With
Else
Err.Clear
With goWord.ActiveDocument.PageSetup
.FirstPageTray = FirstPageTray
.OtherPagesTray = SubsPagesTray
End With
End If
****************************

If the first object on the template is a frame then
the "Page Setup" option is disabled and trying to get at
the object will cause the error as the frame is selected
in word.

How can I move the selection in code to a position that
will exist on all templates so that the "Page Setup"
object will become available.

If there is no frame there when the document is
unprotected I do not have an issue.

Many thanks

Andy
 
A

Andy Smith

Code should have of course read

'Get the document to be opened
goWord.Documents.Open Filename
If goWord.ActiveDocument.ProtectionType <>
wdNoProtection Then
goWord.ActiveDocument.Unprotect "Protected"
End If

'turn error handling off while we see if we can access
the page setup object in a particular way.
On Error Resume Next
'see if we can get at the page setup object this way
sTest = goWord.ActiveDocument.Sections
(1).Range.Paragraphs(1).Range.PageSetup.Application
If Err.Number = 0 Then
With goWord.ActiveDocument.Sections
(1).Range.Paragraphs(1).Range.PageSetup
.FirstPageTray = FirstPageTray
.OtherPagesTray = SubsPagesTray
End With
Else
Err.Clear
With goWord.ActiveDocument.PageSetup
.FirstPageTray = FirstPageTray
.OtherPagesTray = SubsPagesTray
End With
End If


goWord.ActiveDocument.Sections
(1).Range.Paragraphs(1).Range.PageSetup ALWAYS works

goWord.ActiveDocument.PageSetup NEVER works but would be
preferable.

Thanks
 
C

Cindy Meister -WordMVP-

Hi Andy,
How can I move the selection in code to a position that
will exist on all templates so that the "Page Setup"
object will become available.
I don't think you can ensure this, in a general global way,
as there might be something "illegal" in any document that
would be opened. If you say, "How can I set up my templates
to ensure..." then I'd recommend to insert a bookmark at
the position in each template where you want the selection
to be and then do
ActiveDocument.Bookmarks("THeName").Select

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Sep 30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top