Can Excel startup Word?
' This should help you
Sub Wordhdl()
Dim WordApp As Word.Application
Dim WordDoc As Word.Document
Set WordApp = getWord()
Set WordDoc = getDocument(WordApp) ' this will ensure we have an
open document
End Sub
Private Function getWord() As Word.Application
On Error Resume Next
Err.Clear
Set getWord = GetObject(, "Word.Application")
If Err.Number < 0 Then ' iff Word isn't there lets start it
Set getWord = CreateObject("Word.Application")
Err.Clear
End If
getWord.Visible = msoCTrue
End Function
Private Function getDocument(WordApp As Word.Application) As
Word.Document
' Reference active document
On Error Resume Next
Set getDocument = WordApp.ActiveDocument
If Err.Number < 0 Then 'if no document lets create one
Set getDocument = WordApp.Documents.Add()
Err.Clear
End If
End Function
|