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 thedoctopsubroutine:
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.
While I don't have 2013 to test, even on 2010 I have run in to some issues with certain commands which aren't exposed through the
PasteSpecialoptions; specifically those relating to pasting between applications and preserving formatting/etc.
With that in mind, I'm guessing the
Msoprocedure should work. Try:
Several others also you could test:
"PasteBitmap" "PasteGif" "PastePng" "PasteJpeg"