Message box problems

A

aehan

Hello everyone

I'm having a problem with some code. I have created a template in Word 2003
which includes text that may be edited in the template only. The document
created from it is fully protected allowing no edits. I have created a
message box in the This Document module of the template as follows:

Sub AutoOpen()

Dim Response As String
Response = msgbox("Do you want to open the template to edit it? If so,
press Yes." _
& vbCrLf & "To open a document based on the template press No." _
& vbCrLf & "To exit without opening either, press Cancel", vbYesNoCancel
+ vbDefaultButton2)

If Response = vbYes Then
ThisDocument.Activate
CommandBars("Colours").Visible = True
ElseIf Response = vbNo Then
ThisDocument.Close
Documents.Add Template:= _
"C:\Documents and Settings\UserName\Application
Data\Microsoft\Templates\Test Data\Test Template.dot" _
, NewTemplate:=False, DocumentType:=0
ElseIf Response = vbCancel Then ThisDocument.Close
End If

End Sub

I have written an AutoNew macro in a module in the same project as below:

Sub AutoNew()
' Protect Document

ActiveDocument.Protect Password:="secret", NoReset:=False, Type:= _
wdAllowOnlyFormFields, UseIRM:=False, EnforceStyleLock:=False
CommandBars("Task Pane").Visible = False
CommandBars("Colours").Visible = False
End Sub

Everything appears to work perfectly, except that when a protected document
based on the template is re-opened the message box is displayed! Help! What
have I done wrong? Any help would be gratefully received. I've spent a lot
of time trying to work it out and looking through the help group, but
couldn't find an answer.

Thank you all
Aehan
 
T

Tony Jollans

This is working as it should. AutoOpen macros in templates run when
documents based on the template are opened (as well as the template
itself). If you only want the code to run when the template itself is
opened add a line at the beginning something like:

If Not ActiveDocument Is ThisDocument Then Exit Sub
 
A

aehan

Tony, Perfect, thank you so much!
Aehan

Tony Jollans said:
This is working as it should. AutoOpen macros in templates run when
documents based on the template are opened (as well as the template
itself). If you only want the code to run when the template itself is
opened add a line at the beginning something like:

If Not ActiveDocument Is ThisDocument Then Exit Sub
 

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