【问题标题】:Run-time error -2147023170 (800706be) when copy-pasting images from Excel to Word将图像从 Excel 复制粘贴到 Word 时出现运行时错误 -2147023170 (800706be)
【发布时间】:2020-05-28 17:15:20
【问题描述】:

我正在尝试将一些图像从我的 Excel 工作表复制/粘贴到 Word 文件中。有时,它可以完美运行,但我经常会遇到严重的运行时错误“-2147023170 (800706be)”:自动化错误。远程过程调用失败。 消息。谷歌向我展示了这个错误并不孤单,而且它通常是由以下事实引起的,例如范围没有精确定义。不过,我认为它们在我的项目中。

这是我的代码:

Dim wdDoc As Object
Dim wdApp As Object
Set wdApp = CreateObject("Word.Application")
Set wdDoc = wdApp.Documents.Add
Dim wdImg As Object
ThisWorkbook.Worksheets("Backup - Do not change").Shapes("companyLogo").Copy
With wdDoc.Sections(1).Headers(2).Range
    .PageSetup.DifferentFirstPageHeaderFooter = True
    .Paste
    Set wdImg = .InlineShapes(.InlineShapes.Count).ConvertToShape
    With wdImg
       'some specifications
    End With
End With
ThisWorkbook.Worksheets("Backup - Do not change").Shapes("projectLogo").Copy
With wdDoc.Sections(1).Headers(2).Range
    .Paste
    Set wdImg = .InlineShapes(.InlineShapes.Count).ConvertToShape
    With wdImg
       'some specifications
    End With
End With
Application.CutCopyMode = False

错误总是发生在.Paste。我已经尝试过.PasteSpecial DataType:=8 和其他各种方法,但没有帮助。非常欢迎任何帮助!

【问题讨论】:

    标签: excel runtime-error word


    【解决方案1】:

    好吧,我现在没有直接粘贴到标题范围,而是在标题中创建了一个表格,并将图像粘贴到两个不同的单元格中。从那时起,我已经成功地将代码运行了 10 倍以上,所以这似乎解决了这个问题(我希望它保持这样)。不过,仍然不确定是什么原因造成的。

    【讨论】:

      【解决方案2】:

      我想补充一下,因为这是我遇到类似问题时遇到的第一批帖子之一。至少对我来说,解决方案是使用copypicturepastespecial,如下所述:

      Stack Overflow

      尽管搜索了很多,但在我开始输入问题并出现在类似问题列表中之前,我从未出现此线程。希望这可以让其他人免去我要解决的巨大头痛。

      【讨论】:

        猜你喜欢
        • 2012-11-24
        • 1970-01-01
        • 1970-01-01
        • 2022-06-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-02
        • 1970-01-01
        相关资源
        最近更新 更多