• Word Automation from XL (Office 2k)

    Author
    Topic
    #376919

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

    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
    

    However the line “.PageSetup.LeftMargin = CentimetersToPoints(1.5)” bombs out with ther Error Msg
    [indent]


    Run-time error ‘462’:

    The remote server machine does not exist or is unavailable


    [/indent]
    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

    Viewing 2 reply threads
    Author
    Replies
    • #619158

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

      Does that help?

    • #619381

      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.

      • #619409

        Thanks for all replies, the create method seems to have done the trick. smile 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 smile

        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

    • #619382

      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.:

      PageSetup.LeftMargin = objWordApp.CentimetersToPoints(1.5) 

      Gary

    Viewing 2 reply threads
    Reply To: Word Automation from XL (Office 2k)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: