K
kiln
I use VBA to generate Word 2000 docs, calling from Access 2000. The doc
that is build is for use later, so I don't need Word to open and show
the doc at creation time. Everything in the code below works fine,
except that if an instance of Word is already open when the code is run,
the open Word instance sort of goes dead. What I mean is, the toolbars
are dead; they don't respond any more. The doc that was open is
editable. Is there something in the code below that fouls up the running
instance of word?
Thanks
Private Function CreateDoc()
Dim objWord As Object
Dim boolInitobjWord As Boolean
Dim strPath As String
If fIsAppRunning("Word") Then
Set objWord = GetObject(, "Word.Application")
boolInitobjWord = False
Else
Set objWord = CreateObject("Word.Application")
boolInitobjWord = True
End If
strPath = "c:\whatever\anewdoc.doc"
objWord.Documents.Add "c:\whatever\mytemplate.dot"
With objWord.ActiveDocument.Bookmarks
.Item("SomeName").Range.Text = FullName
End With
objWord.ActiveDocument.SaveAs strPath
objWord.ActiveDocument.Close
ExitHere:
If boolInitobjWord = True Then
objWord.Quit
End If
Set objWord = Nothing
Exit Function
End Function
that is build is for use later, so I don't need Word to open and show
the doc at creation time. Everything in the code below works fine,
except that if an instance of Word is already open when the code is run,
the open Word instance sort of goes dead. What I mean is, the toolbars
are dead; they don't respond any more. The doc that was open is
editable. Is there something in the code below that fouls up the running
instance of word?
Thanks
Private Function CreateDoc()
Dim objWord As Object
Dim boolInitobjWord As Boolean
Dim strPath As String
If fIsAppRunning("Word") Then
Set objWord = GetObject(, "Word.Application")
boolInitobjWord = False
Else
Set objWord = CreateObject("Word.Application")
boolInitobjWord = True
End If
strPath = "c:\whatever\anewdoc.doc"
objWord.Documents.Add "c:\whatever\mytemplate.dot"
With objWord.ActiveDocument.Bookmarks
.Item("SomeName").Range.Text = FullName
End With
objWord.ActiveDocument.SaveAs strPath
objWord.ActiveDocument.Close
ExitHere:
If boolInitobjWord = True Then
objWord.Quit
End If
Set objWord = Nothing
Exit Function
End Function