Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Jun 2001
    Location
    Maidstone, Kent, England
    Posts
    398
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Word Automation from XL (Office 2k)

    I am trying to start Word from Excel to make a report using the following code snippet

    <pre>Sub tempCreateWord()
    Dim objwordApp As New Word.Application
    Dim objwordDoc As Word.Document
    objwordApp.Visible = True
    Set objwordDoc = objwordApp.Documents.Add
    With objwordDoc
    .PageSetup.LeftMargin = CentimetersToPoints(1.5)
    .PageSetup.RightMargin = CentimetersToPoints(1.5)
    End With
    Set objwordDoc = Nothing
    End Sub
    </pre>


    However the line ".PageSetup.LeftMargin = CentimetersToPoints(1.5)" bombs out with ther Error Msg
    <hr>Run-time error '462':

    The remote server machine does not exist or is unavailable<hr>
    If Word is open before running the code it runs OK but if word is closed it gives the error about every other attempt to run it!
    First try works OK. Close Word and run again it crashes, end the code close the copy of Word that it opened and run it again it will run OK.
    I have checked in Task Manager in-between running it that there are no copies of Word running.

    Any help appreciated

    Peter

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Automation from XL (Office 2k)

    Do you use Norton Auntie Virus?
    If so, disable the NAV Office plug-in, but enable NAV's AutoProtect.

    Does that help?

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Word Automation from XL (Office 2k)

    PageSetup might be having a timing problem. I believe Word probably wants to sniff the printer driver before you change those settings; maybe Word is "busy"?

    Another possibility is that New Word.Application doesn't seem to be 100% reliable. See this recent thread for an example and alternative approach.

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Word Automation from XL (Office 2k)

    Peter,

    Another thing to try would be to fully qualify the call to the 'CentimetersToPoints' method; since this method exists in both the Excel and Word VBA object models, perhaps that can be causing a problem. Ex.:

    <pre>PageSetup.LeftMargin = objWordApp.CentimetersToPoints(1.5) </pre>


    Gary

  5. #5
    3 Star Lounger
    Join Date
    Jun 2001
    Location
    Maidstone, Kent, England
    Posts
    398
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Automation from XL (Office 2k)

    Thanks for all replies, the create method seems to have done the trick. <img src=/S/smile.gif border=0 alt=smile width=15 height=15> I will have to do some reading to try and find out why now!

    I am running McAfee not Norton which is just as well as I am sure that our IT Dept. would not let me modify any settings to the virus protection.

    Fully Qualifing the call made no difference but was certainly the easiest to try <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    Edited Later. oops I need to learn to read properly! Fully Qualyfing did the trick when I followed the example properly!

    Many thanks for all the help

    Peter

Posting Permissions

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