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