Run time Error '462' The remote server machine does not exist or is unavailable

gruntingmonkey

Active Member
Joined
Mar 6, 2008
Messages
444
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have created some code to open a word template from Excel and then fill in some details via the Bookmarks, however every other time I run it, I get the following error "Run time Error '462' The remote server machine does not exist or is unavailable".

I have tried to understand what bit of my code is wrong through other peoples explanations but I just can't find it!

Can Anyone help out?


Code:
Sub CreateContract()

Dim ConTemp As String
Dim wdApp As Word.Application
Dim wdDoc As Word.Document

'''Excel references
Dim AccID As String, Serv As String, clName As String

ConTemp = "C:\Users\jess\Documents\Custom Office Templates\Contract Template.dotx"

'''Collects the data from Excel
Workbooks(ThisWorkbook.Name).Activate
AccID = Sheets("DataInput").Cells(7, 4).Value
Serv = Sheets("DataInput").Cells(8, 4).Value
clName = Sheets("DataInput").Cells(10, 4).Value
  
    Set wdApp = CreateObject("Word.Application")
   ' Set wdApp = New Word.Application
    '''Opens the template
    With wdApp
        .Visible = True
        .Activate
        .Documents.Open ConTemp
        
    Set wdDoc = Documents(ConTemp)
    
        With wdDoc
            '''find the right Bookmark
            .Bookmarks("AccountID").Range.Text = AccID
            .Bookmarks("ServiceType").Range.Text = Serv
            .Bookmarks("ClientName").Range.Text = clName
        
            .SaveAs2 Filename:="C:\Users\jess\OneDrive\Contract Creation\Test Contracts\Test1.docx"
            .Close
            
        End With
        
    End With
    
    wdApp.Quit
 
    Set wdApp = Nothing
    Set wdDoc = Nothing


End Sub
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Change this:

Rich (BB code):
Set wdDoc = Documents(ConTemp)

to this:

Rich (BB code):
Set wdDoc = wdApp.Documents(ConTemp)
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top