Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2007

Tip: Looking for answers? Try searching our database.

Message box problems

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
aehan - 27 Sep 2007 11:01 GMT
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
Tony Jollans - 27 Sep 2007 12:41 GMT
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

Signature

Enjoy,
Tony

> Hello everyone
>
[quoted text clipped - 50 lines]
> Thank you all
> Aehan
aehan - 27 Sep 2007 14:24 GMT
Tony, Perfect, thank you so much!
Aehan

> This is working as it should. AutoOpen macros in templates run when
> documents based on  the template are opened (as well as the template
[quoted text clipped - 57 lines]
> > Thank you all
> > Aehan
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.