excel - 将图像从 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
和其他各种事情,但没有帮助。非常欢迎任何帮助!
解决方案
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.
推荐阅读
- laravel - npm run dev:[webpack-cli] 错误:找不到模块“gensync”
- material-ui - 将素材ui从v4升级到v5后,jss-rtl插件不起作用
- powershell - 将 Powershell 命令的输出保存到变量中
- java - 无效 XML:第 6 行错误:元素类型“hr”必须由匹配的结束标记“”终止
- huggingface-transformers - 导入 Transformer 时无法引用 Huggingface AutoTokenizer
- angular - 如何将 Angular 9 登录页面连接到 Spring Boot 应用程序?
- python - 由于设置中的 INSTALLED_APPS 导致 Django Elastic Beanstalk 部署错误
- ios - 如何在 hasura 中修改 GraphQL 响应?
- javascript - AWS lambda 阻止 CORS 请求
- python - 如何在python中获取单词的字母数?