Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Document_Open() HELP!! 1

Status
Not open for further replies.

buba

Technical User
Dec 31, 2002
3
US
friends,
i have a template 'x.dot'. whenever new documents are created using this template i want the Document_Open()
subroutine for this new document to include some codes, say, 'msgbox "hello"' which are saved with it.. so that whenever the documents based on this template are opened it displays "hello" msgbox.
Regards
buba
 
you need to set a reference to "Microsoft Visual Basic for Applications Extensibility"

put this code in your template project.
when a new document is created based on your template, this code adds the required code to the new document.

Code:
Option Explicit

Private Sub Document_New()
  Dim vbc As VBComponent
  Dim strCode As String
  
  strCode = "Private Sub Document_Open()" & vbCrLf & _
            "  MsgBox ""hello""" & vbCrLf & _
            "End Sub"
  
  For Each vbc In ActiveDocument.VBProject.VBComponents
    If vbc.Type = vbext_ct_Document Then
      vbc.CodeModule.AddFromString strCode
    End If
  Next vbc
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top