Reputation: 5765
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.
Upvotes: 1
Views: 995
Reputation: 53623
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 Paste
or PasteSpecial
options; specifically those relating to pasting between applications and preserving formatting/etc.
With that in mind, I'm guessing the Mso
procedure should work. Try:
wd.Application.CommandBars.ExecuteMso "PasteAsPicture"
Several others also you could test:
"PasteBitmap"
"PasteGif"
"PastePng"
"PasteJpeg"
Upvotes: 2