View Single Post
 
Old 12-29-2010, 02:10 PM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2000
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Dan,

Whos's Kevin?

The issue with the AutoOpen macro is that it won't run as a Private sub. Delete 'Private' and it should run. However, if the document is protected, as you say it is, you'll get a run time error. The document needs to be unprotected before you can change the design mode.

Try as I might, though, I can't get Word to protect a document and leave it in design mode. So developing & testing code to get a protected document out of design mode is somewhat problematic ...

Give the following a go. It'll work with a protected document and explcity turns off design mode.
Code:
Sub AutoOpen()
' Runs when this document is opened.
Dim Pwd As String ' String variable to hold passwords for protected documents
Dim pState As Boolean ' Document protection state flag
With ActiveDocument
  ' Insert your document's password between the double quotes on the next line
  Pwd = ""
  ' Initialise the protection state
  pState = False
  ' If the document is protected, unprotect it
  If .ProtectionType <> wdNoProtection Then
    ' Update the protection state
    pState = True
    ' Unprotect the document
    .Unprotect Pwd
  End If
  ' Swith off Design Mode
  .FormsDesign = False
  ' If the document was protected, reprotect it, preserving any formfield contents
  If pState = True Then .Protect wdAllowOnlyFormFields, Noreset:=True, Password:=Pwd
End With
End Sub
The code can be run manually or by opening the document.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote