-
My program uses automation to load a template word file into MSWord. In vb code the syntax is
<code>
Set wdApp = CreateObject("word.application")
wdApp.Documents.Open (c:\MyTempFile.dot)
</code>
In this way, the Opened file name is MyTempFile, when user tries to save it , it overwrites the template file. Anyway to Open the template file into a default file "document1"?
Or is there a way to setup file save path from VB code using macro?
thanks for your help?
-
WinLa, what you have done is actually asked Word to Open a NEW document using the template in order to make Document1.
Its like going into Windows Explorer and double clicking on a Word Template there... You will notice that it doesn't open the template itself but a NEW document "based" on the template.
What you need to do to correct this problem is to have a read of the Documents.Open and similar areas where it talks about templates... I don't know exactly but I know that there is a parameter that allows you to set the "type" of file you are opening... by setting this to template you are telling it to load THE template not a NEW document based on that template.
Hope it helps
-
Hi,
My project also uses a template. It opens the template as document1 but then when I go to close the print preview it asks me if I want to save the template even though I have used:
oword.Quit SaveChanges:=wdDoNotSaveChanges
Set oWord = Nothing
I do not want to save the document1 or alter the template.
Also,
When I click on word after this it opens word with that template and it gives me an error when I try to close it?????
Please help, as the project is finished only for this.
-
I think you want to use the Add method rather than the Open method of the Documents collection of the Word Application object. I believe Open is for opening an existing document, whereas Add is for creating a new document (and it gives you the option of using a template path).
For ex:
wdApp.Documents.Add "c:\MyTempFile.dot"
If you omit the template argument from the Add method it uses the 'Normal.dot' template.
Good luck,
Paul