TheShaunMichael
Board Regular
- Joined
- Oct 24, 2009
- Messages
- 57
Hello fellow VBA-ers,
I have a very long macro that uses data in excel to create estimates with paragraphs, tables, pictures and so on. It works perfectly every other time I run it. When it fails, I get run time error 462 and it points me to what I have colored below in red. This is the very beginning of my macro and I believe it has something to do with how I've set the wrdApp and wrdDoc labels.
Any help is greatly appreciated!
Set wrdApp = CreateObject("Word.Application")
Set EI = Worksheets("Estimate Info")
Z = ActiveCell.Row
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Add
wrdDoc.Content.Style = "No Spacing"
wrdDoc.PageSetup.DifferentFirstPageHeaderFooter = True
wrdDoc.Sections(1).Headers(wdHeaderFooterFirstPage).Shapes.AddPicture ("C:\Users\User\Desktop\Picture1.jpg")
wrdDoc.Sections(1).Headers(wdHeaderFooterFirstPage).Shapes.AddPicture ("C:\Users\User\Desktop\Picture2.jpg")
With wrdDoc.Sections(1).Headers(wdHeaderFooterFirstPage).Shapes(1)
.Left = InchesToPoints(0)
.RelativeHorizontalPosition = wdRelativeHorizontalPositionLeftMarginArea
.Top = InchesToPoints(0.5)
.RelativeVerticalPosition = wdRelativeVerticalPositionParagraph
.Width = 70
End With
I have a very long macro that uses data in excel to create estimates with paragraphs, tables, pictures and so on. It works perfectly every other time I run it. When it fails, I get run time error 462 and it points me to what I have colored below in red. This is the very beginning of my macro and I believe it has something to do with how I've set the wrdApp and wrdDoc labels.
Any help is greatly appreciated!
Set wrdApp = CreateObject("Word.Application")
Set EI = Worksheets("Estimate Info")
Z = ActiveCell.Row
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Add
wrdDoc.Content.Style = "No Spacing"
wrdDoc.PageSetup.DifferentFirstPageHeaderFooter = True
wrdDoc.Sections(1).Headers(wdHeaderFooterFirstPage).Shapes.AddPicture ("C:\Users\User\Desktop\Picture1.jpg")
wrdDoc.Sections(1).Headers(wdHeaderFooterFirstPage).Shapes.AddPicture ("C:\Users\User\Desktop\Picture2.jpg")
With wrdDoc.Sections(1).Headers(wdHeaderFooterFirstPage).Shapes(1)
.Left = InchesToPoints(0)
.RelativeHorizontalPosition = wdRelativeHorizontalPositionLeftMarginArea
.Top = InchesToPoints(0.5)
.RelativeVerticalPosition = wdRelativeVerticalPositionParagraph
.Width = 70
End With