Home  |   French  |   About  |   Search  | mvps.org  

What's New
Table Of Contents
Credits
Netiquette
10 Commandments 
Bugs
Tables
Queries
Forms
Reports
Modules
APIs
Strings
Date/Time
General
Downloads
Resources
Search
Feedback
mvps.org

In Memoriam

Terms of Use


VB Petition

Modules: Opening a new Word document based on a template through Automation

Author(s)
Dev Ashish

   To open a new Word document based on an existing template, we need to specify a value for the Template argument of the Add method of the Documents collection. 

    If the template file (.DOT) is saved in the UserTemplates path,  we can use the pre-defined contant wdUserTemplatesPath. Otherwise, we will need to supply the complete path to the template file.

'****** Code Start ********
'This code was originally written by Dev Ashish
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code Courtesy of
'Dev Ashish
'
Private mobjWordApp As Word.Application

Private Sub Command1_Click()
Const conTEMPLATE_NAME = "\Templates\merge.dot"

   Set mobjWordApp = New Word.Application
   With mobjWordApp
      .Visible = True
      .WindowState = wdWindowStateMaximize
      .Documents.Add Template:=(.Options.DefaultFilePath( _
               wdUserTemplatesPath) _
               & conTEMPLATE_NAME)
   End With
End Sub
'****** Code End ********

1998-2010, Dev Ashish & Arvin Meyer, All rights reserved. Optimized for Microsoft Internet Explorer