首页 > 解决方案 > 将图像从 Excel 复制粘贴到 Word 时出现运行时错误 -2147023170 (800706be)

问题描述

我正在尝试将一些图像从我的 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和其他各种事情,但没有帮助。非常欢迎任何帮助!

标签: excelruntime-errorword

解决方案


Okay so instead of pasting directly to the header range, I now created a table within the header and paste the images into two different cells. Since then I've successfully run the code for more than 10x so it seems like this fixed the issue (I hope it stays like this). Still not sure what caused it, though.


推荐阅读