Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    314
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Word VBA Automation bug? (Office 2000 SP 1A WinXP)

    I have been trying to write a routine that will get around some of Word VBA's Automation anomolies and have almost succeeded except that the following gets a runtime error number 462 "the remote server machine does not exist or is unavailable" on the line:
    .Tables.Add Range:=Selection.Range, NumRows:=2, NumColumns:= _
    1, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
    wdAutoFitFixed

    BUT ONLY EVERY SECOND TIME I RUN THE CODE.
    It runs fine the first, third, fifth times etc.
    Any ideas what is wrong please?
    (see attached file for complete routine)

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Word VBA Automation bug? (Office 2000 SP 1A WinXP)

    You haven't qualified Selection.Range, you MUST use either .Range (since you are in a With ... End With block referring to the selection) or use objWord.Selection.Range instead of just Selection.Range. Also, I would apply .Tables.Add to the document object instead of to the selection:

    docWord.Tables.Add Range:=.Selection.Range, ...

    Other remarks:

    1. You should declare docActive as Word.Document, not as Document.
    2. You haven't declared Document. Apart from that, I would never give a variable the same name as a type.
    3. You probably don't require variable declaration. You should! Set it in Tools | Options, and insert Option Explicit at the top of already existing modules.
    4. You use an unqualified reference to Selection in one other place. Change that to objWord.Selection.
    5. wdWindowStateMaximise should be wdWindowStateMaximize.
    6. Why use docWord.Application? That is the same as objWord.
    7. Why use docWord.Application.ActiveDocument? Just docWord should be enough.

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    314
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word VBA Automation bug? (Office 2000 SP 1A WinXP)

    Thanks Hans,
    I copied some code that worked in Word directly into Access and that Selection.Range escaped my notice.
    That was it really. All the other points are helpful too (I'm more familiar with Access VBA than Word so it's
    all grist for the mill.
    Code appears to work correctly now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •