Saving word document from excel

Challis

New Member
Joined
Oct 22, 2017
Messages
21
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.
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
Any help appreciated.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Try
Code:
objWord.ActiveDocument.SaveAs
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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