I have an Excel workbook which generates a Word document. At one point it copies an Excel image into the heading of the generated Word document. This code has worked in Office 2003, 2007, and 2010, but now in 2013 it fails on the Paste statement with a generic automation error in the Paste method. I'm hoping someone can help me make this work in Office 2013. To duplicate, define a macro workbook with a worksheet called "Logo" containing a single shape, add the following code, and execute the doctop subroutine:
Const wdCollapseEnd = 0
Const wdHeaderFooterPrimary = 1
Const wdPrintView = 3
Const wdSeekCurrentPageHeader = 9
Const wdSeekMainDocument = 0
Sub doctop()
Set wd = CreateObject("Word.Document")
wd.Application.Visible = True
' insert heading with logo
Worksheets("Logo").Shapes(1).CopyPicture xlScreen, xlBitmap
With wd.ActiveWindow.View
.Type = wdPrintView
.SeekView = wdSeekCurrentPageHeader
End With
With wd.sections(1).headers(wdHeaderFooterPrimary).Range
.Collapse wdCollapseEnd
.Paste
End With
wd.ActiveWindow.View.SeekView = wdSeekMainDocument
End Sub
Thanks in advance for your help.
wd.Application.CommandBars.ExecuteMso "PasteAsPicture"(or "PasteBitmap", "PasteGif", "PastePng", "PasteJpeg"). - David Zemens