Log in

View Full Version : Solved: Help with opening a word template



SilverSN95
07-30-2009, 09:49 AM
Hi again,
I'm having an issue that again probably isn't a hard one to fix but I am currently stuck on how to solve it.
The problem: In my macro, I would like to open a .dot file, and then fill it with information from the calling excel WB. This works fine, however if I leave the word file open (which of course is now a .doc) and re-run the macro, it just uses that open instance and reinserts the same data.
In a similar macro I wrote for an excel template, when I open new instances, it creates a new one with a number added to the end of the filename. That is the behavior I would like to see from my macro opening the .dot.
Here is how I define and open it:

Dim wdApp As Word.Application
Application.ScreenUpdating = False
Dim sourceWB As Workbook
Dim dest As Word.Document
Dim docLocation As String
...
On Error Resume Next
Set wdApp = GetObject(, "Word.Application") 'Look for instance of Word
If Err.Number <> 0 Then
Set wdApp = CreateObject("Word.Application") ' Otherwise create one
End If
On Error GoTo 0
.....

docLocation = sourceWB.Sheets("Sheet1").Range("D11").Value 'location of template adress

Set dest = wdApp.Documents.Open(docLocation) ' Open template from word instance

wdApp.Visible = True 'Allow user to see word application
dest.Activate



Edit: The macro seems to be opening the template directly, so I think I just need to know how to open an instance (terminology?) of the template and not the template itself.

Let me know if you would like to see the entire macro.
Any help greatly appreciated!

macropod
07-30-2009, 05:38 PM
Hi SilverSN95,

Try changing:
Set dest = wdApp.Documents.Open(docLocation) ' Open template from word instance
to:
Set dest = wdApp.Documents.Add(docLocation) ' Create a new Word document based on the dest template

SilverSN95
07-31-2009, 06:10 AM
Thanks, this is what I needed. Strangely enough my other macro using xlt's seemed to work fine with .open() but I'm sure there is a difference somewhere else in the code.