I got a VBA project from an old work colleague who is already retired and despair of it.
The project itself works, but I have to change a function:
Documents.Add Template:= _
"c:\word\Link.dot", _
NewTemplate:=False, DocumentType:=0
Here a new document (another Word file) is created with a template. The problem is this template relates also data from another project "Common". Basically, "Documents.Add Template:= _"c:\word\Link.dot"" in Link.dot the Document_Open() is executed and the Common project is initialized.
Private Sub Document_Open()
Common.Initialize
End Sub
The Problem is I don't want a second document to be opened by Documents.add, it should use the already active document, not a 2nd.
I have already tried these 2 variants:
#1
Dim oDoc As Document
Set oDoc = ActiveDocument
oDoc.AttachedTemplate = "c:\word\Link.dot"
#2
ActiveDocument.AttachedTemplate = "c:\word\Link.dot"
Unfortunately,nothing happens to both of them, even no RuntimeError. I think it's because Document_Open() wasn't executed. Maybe I'm on the wrong track....
Does anyone have any advice?
CodePudding user response:
Document_Open() responds to the Open event. As you are not opening a document when attaching the template it will not execute.
You can execute the code directly though.
ActiveDocument.AttachedTemplate = "c:\word\Link.dot"
Common.Initialize
