DouglasWicker
New Member
- Joined
- Aug 8, 2017
- Messages
- 38
Morning All,
I have an issue with he code below;
The code selects objects from my excel workbook and pastes it into a new word document fine, however I get an error when adjusting the margins.
The error I get is a Run-time error '462': - The remote server machine does not exist or is unavailable.
It is also worth mentioning that the code works flawlessly when running from the VBA window, just doesn't work when using the macro button.
Any ideas??
I have an issue with he code below;
The code selects objects from my excel workbook and pastes it into a new word document fine, however I get an error when adjusting the margins.
The error I get is a Run-time error '462': - The remote server machine does not exist or is unavailable.
It is also worth mentioning that the code works flawlessly when running from the VBA window, just doesn't work when using the macro button.
Any ideas??
Code:
ActiveSheet.Shapes.Range(Array("Group 329", "Group 302", "Group 320", _ "Group 293", "Group 284", "TextBox 241", "TextBox 240", "TextBox 242", _
"TextBox 243", "Group 275", "TextBox 244", "TextBox 245", "Group 257", _
"Group 266", "TextBox 246", "TextBox 239", "Group 75", "TextBox 238")).Select
Selection.Copy
Dim wdApp As Object
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
On Error GoTo 0
If wdApp Is Nothing Then
Set wdApp = CreateObject(Class:="Word.Application") 'INITIALIZE THE OBJECT.
wdApp.Visible = True 'OPEN THE WORD FILE.
wdApp.Documents.Add 'Add new Page
wdApp.Activate 'Activate Page
wdApp.Selection.Paste 'Paste Report
'set Margins
wdApp.Selection.PageSetup.TopMargin = CentimetersToPoints(2.25)
wdApp.Selection.PageSetup.BottomMargin = CentimetersToPoints(0)
wdApp.Selection.PageSetup.RightMargin = CentimetersToPoints(0)
wdApp.Selection.PageSetup.LeftMargin = CentimetersToPoints(1.4)
Else
MsgBox "No word documents can be open to generate a report."
End If
'Clean up the Object when Finished
Set wdApp = Nothing