Results 1 to 5 of 5

Thread: Using Word

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Posts
    153

    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.

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    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.

  3. #3
    jim mcnamara
    Guest
    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.

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    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...

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Posts
    153
    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
  •  



Click Here to Expand Forum to Full Width