Hi all,
I am doing a letter generation with word.
All I want to do is, to check if any instance of Word is open.
If opened I need to use the existing word instance
and if not I want to open a new instance of word.
Kindly help me out.
Printable View
Hi all,
I am doing a letter generation with word.
All I want to do is, to check if any instance of Word is open.
If opened I need to use the existing word instance
and if not I want to open a new instance of word.
Kindly help me out.
Use GetObject instead of CreateObject to get a reference to a started session of Word. If GetObject returns an error Word isn't started so use CreateObject instead.
Best regardsCode:Private word As Word.Application
Private Sub StartWord()
On Error Resume Next
Set word = GetObject("", "Word.Application")
If Err.Number <> 0 Then
'Word isn't started so we use CreateObject instead
Set word = CreateObject("", "Word.Application")
End If
'the rest of the code
End Sub
Using a null for the first argument of GetObject rather than no argument causes GetObject to start Word if it is not already started.Code:Dim MyWord as Object
Set MyWord = GetObject("","Word.Basic")
You're right. You should pass an empty string in the first argument. This is what happens when you type the code directly in the post.Quote:
Originally posted by jim mcnamara
Using a null for the first argument of GetObject rather than no argument causes GetObject to start Word if it is not already started.
I've edited my original post...
Hi guys,
The code isn't using old instance of word. Instead its opening
a new instance and as I am using a template, I am able to open a document using the template but unable to replace certain words using .Execute method of the Active Document object.
...and i get the error as follows.
4248 : This command is not available because no document is open.
I am using Word 97.