Okay, I'm stuck. I have a command button that collects data from the bottom row of a table in excel and populates bookmarks in a word template. The code seems to work upto the point where it saves the created word document to a file path. The error I'm getting is "remote server machine does not exist...". I was initially trying activate.document but now understand excel does not recognise this function. Hence i added the ojbdoc line but don't understand how to execute it.
Any help appreciated.
Code:
Private Sub GenerateReport_Click()
Dim objWord As Object
Dim ws As Worksheet
Dim btmrow As Integer
Dim objdoc
btmrow = Cells(Rows.Count, "A").End(xlUp).Row
Set ws = ThisWorkbook.Sheets("Register")
Set objWord = CreateObject("Word.Application")
Set objdoc = objWord.documents.Add
objWord.Visible = True
objWord.documents.Open "\\BWISHARE1\SHARE\ABU Materials and Inspection Engineering\Gorgon\Team\Working\SCJW\Process Development\Report Register Development\Templates\Pressure Piping Inspection Report Template.docm"
With objWord.ActiveDocument
.Bookmarks("Date").Range.Text = ws.Cells(btmrow, 11).Value
.Bookmarks("EquipmentNumber").Range.Text = ws.Cells(btmrow, 7).Value
.Bookmarks("Name").Range.Text = ws.Cells(btmrow, 13).Value
.Bookmarks("ReportNumber").Range.Text = ws.Cells(btmrow, 10).Value
.Bookmarks("Unit").Range.Text = ws.Cells(btmrow, 6).Value
.Bookmarks("WorkOrder").Range.Text = ws.Cells(btmrow, 3).Value
.Bookmarks("Location").Range.Text = ws.Cells(btmrow, 5).Value
Dim Fname As String
Dim Fpath As String
Fpath = "O:\ABU Materials and Inspection Engineering\Gorgon\Team\Working\SCJW\Process Development\Report Register Development\Templates\Saved"
Fname = ws.Cells(btmrow, 10).Value
objdoc.SaveAs Filename:=Fpath & "\" & Fname
End With
Set objWord = Nothing
End Sub