Elmo Erasmus
asked on
run time error 462 the remote server machine does not exist
Hi All
When i run the code below for the first time i receive the error as per the title. When i run it a second time it run through correctly. I have read a bit on it and see that it could be late bindings or Implicit references but i don't really see if and where this would apply in the code below.
The code breaks on this line
Thanks in advance
Elmo
When i run the code below for the first time i receive the error as per the title. When i run it a second time it run through correctly. I have read a bit on it and see that it could be late bindings or Implicit references but i don't really see if and where this would apply in the code below.
The code breaks on this line
ActiveDocument.MailMerge.Fields.Add Range:=WdDoc.Bookmarks(cell.Offset(0, 2).Value).Range, Name:=txt & cell.Offset(0, 3).Value
Sub DoMerge()
Dim appWd As Word.Application
Dim WdDoc As Word.Document
Dim strBookFullName As String
Dim cell As Excel.Range
'Dim wdFind As Object
Dim txt As String
'Dim MyDoc As String
strBookFullName = ActiveWorkbook.FullName
Set appWd = CreateObject("Word.Application")
appWd.Visible = True
With appWd
Set WdDoc = appWd.Documents.Open("C:\Users\Elmo\Documents\Aaron\2nd Project 2017\WorkingOn\VendorRebateClientDoc4March17_2.docx")
WdDoc.Activate
WdDoc.MailMerge.OpenDataSource Name:=(strBookFullName), _
ReadOnly:=True, LinkToSource:=0, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto, _
Connection:="", SQLStatement:="SELECT * FROM `MergeRange`", SQLStatement1:=""
'Set wdFind = appWd.Selection.Find
'finds text in word doc and replace with merge field
For Each cell In Range("MergeText")
'wdFind.Text = cell.Value
'MyDoc = WdDoc.Range.Text
txt = cell.Offset(0, 1).Value
ActiveDocument.MailMerge.Fields.Add Range:=WdDoc.Bookmarks(cell.Offset(0, 2).Value).Range, Name:=txt & cell.Offset(0, 3).Value
Next cell
.ActiveDocument.MailMerge.Execute
.ActiveDocument.SaveAs "C:\Users\Elmo\Documents\Aaron\From Client\Output\test2.docx"
End With
End Sub
Thanks in advance
Elmo
ASKER
Hi MarcoShadow
Now it works on the first run but gives the same error on the second run
Now it works on the first run but gives the same error on the second run
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I found the answer on my own. The answers provided did nothing to solve the problem
Open in new window
To this:Open in new window