gruntingmonkey
Active Member
- Joined
- Mar 6, 2008
- Messages
- 444
- Office Version
- 365
- Platform
- 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?
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