|
-
Jul 9th, 2001, 06:31 AM
#1
Thread Starter
Addicted Member
Using Word
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.
there r no alternatives 4 hardwork.
-
Jul 9th, 2001, 06:40 AM
#2
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.
Code:
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
Best regards
Last edited by Joacim Andersson; Jul 9th, 2001 at 07:12 AM.
-
Jul 9th, 2001, 07:03 AM
#3
Code:
Dim MyWord as Object
Set MyWord = GetObject("","Word.Basic")
Using a null for the first argument of GetObject rather than no argument causes GetObject to start Word if it is not already started.
-
Jul 9th, 2001, 07:28 AM
#4
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.
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.
I've edited my original post...
-
Jul 9th, 2001, 09:06 AM
#5
Thread Starter
Addicted Member
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.
there r no alternatives 4 hardwork.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|