首页 文章

将Excel图像粘贴到Word Headers 不在Office 2013中工作

提问于
浏览
1

我有一个生成Word文档的Excel工作簿 . 有一次,它将Excel图像复制到生成的Word文档的 Headers 中 . 此代码在Office 2003,2007和2010中有效,但现在在2013年,它在Paste语句中失败,并在Paste方法中出现通用自动化错误 . 我希望有人可以帮我在Office 2013中完成这项工作 . 要复制,请使用包含单个形状的名为"Logo"的工作表定义宏工作簿,添加以下代码,然后执行 doctop 子例程:

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

在此先感谢您的帮助 .

1 回答

  • 1

    虽然我没有通过 PastePasteSpecial 选项暴露出来;特别是那些与应用程序之间粘贴和保留格式/等相关的内容 .

    考虑到这一点,我猜测 Mso 程序应该有效 . 尝试:

    wd.Application.CommandBars.ExecuteMso "PasteAsPicture"
    

    其他几个你也可以测试:

    "PasteBitmap" 
    "PasteGif"
    "PastePng"
    "PasteJpeg"
    

相关问题