Runtime Error 462 when Running Code to Export Excel Values into Word Bookmarks

  • Hi Oxgrid family, ----> z Ozgrid

    I'm hoping for some direction on how to correct my VBA code. I wrote the below code to pull certain pieces of information from an Excel file and insert them into specific bookmarks within a Word template. I've verified that the Bookmarks exist and are valid, and am pretty sure that I'm missing something obvious as I don't code in VBA much. When I run this code, I get a Runtime Error 462 (The remote server machine does not exist or is not available).

    Any help would be appreciated, and thank you! Nikki

    Edited once, last by Carim ().

  • Carim

    Added the Label Cross Post
  • It's likely that the error is caused by the line:

    Set wdDoc = wdApp.Documents.Open(FilePath)

    Since you've already opened the document on the previous line, you don't need to open it again. Try removing this line and see if it resolves the issue. Additionally, it's good practice to close the document and application after you're done with them. You can do this with the following lines:

    wdDoc.Close savechanges:=False

    Place these lines at the end of your code after you're done with the Word document.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!