Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Lorraine Stephens   on Mar 01 In MS Office Category.

  
Question Answered By: Cedric Sanders   on Mar 01

You can modify the Word Templates to force them to always open as New
Documents by sticking this code into the Document_Open event.

Private Sub Document_Open()

'this code is for template  and prevents
'the user from accidentally opening template
'in development mode...create standard document

'turns off repagination and screen updating
'to allow automation to work faster and
'less chance of template corruption or crashing

Options.Pagination = False
Application.ScreenUpdating = False

Dim intDocumentType
Dim strTemplateName As String
Dim strTemplatePath As String

'The following allows the entire project
'to know which template is being worked with
'and it's path. This prevents from having
'to place the template in a specific
'Word template directory. Both are Globals

'gets the full path/name of the active template
strTemplateName = Templates(1).FullName

'gets Path to Template and pads with "\" if required
strTemplatePath = Templates(1).Path
If Right(strTemplatePath, 1) <> Application.PathSeparator Then
strTemplatePath = strTemplatePath & Application.PathSeparator
End If

intDocumentType = ActiveDocument.Type

'*******************************************
'COMMENT OUT ALL INDENTED CODE BELOW WHEN WORKING
'ON TEMPLATE IN DESIGN MODE OR CHANGES
'WON'T BE PROPERLY SAVED. TURN IT BACK ON
'FOR FINAL SO USER CAN'T ACCIDENTALLY
'ACCESS MASTER TEMPLATE DESIGN
'********************************************

If intDocumentType = 1 Then
Documents.Add Template:=strTemplateName
Documents(strTemplateName).Close
SaveChanges:=wdDoNotSaveChanges
End If

End Sub

Share: 

 
 


Tagged: