MS Word 宏...无法插入 PNG

发布于 2024-10-10 17:08:41 字数 848 浏览 1 评论 0原文

有人在使用 VBA 宏将 PNG 文件插入 Word 文档时遇到问题吗?

我有一个 MS Word 文档,其中包含非常大的图像文件目录列表,其中一张桌子。我被要求通过在名称前面插入相应的图像来更新文档。

现在,如果我手动输入图像(使用 Insert|Image|From File),我就能够成功放置 PNG 图像...所以我决定编写一个快速的 VBA 宏来插入我的形象。以下是代码示例:

Dim myFile  As String
Selection.SelectCell
Selection.Copy
myFile = _
   Chr(34) & "C:\Documents and Settings\...\Project\Images\" _
   & Left(Selection.Text, Len(Selection.Text) - 2) & Chr(34)

Selection.InlineShapes.AddPicture _
   FileName:=myFile, LinkToFile:=False, SaveWithDocument:=True

结果:

  • 每当我执行宏时,都会收到“无法转换”错误对话框,并且没有插入图像。
  • 我什至更改了代码以调用 wdDialogInsertPicture 对话框,并且效果很好。

这非常令人困惑......使用手动流程,插入可以工作,但是使用自动解决方案,插入不起作用

有什么想法或建议吗?

Has anyone had problems inserting a PNG file into a word document, using a VBA Macro?

I have an MS Word document that contains a very large directory listing of image files, inside a table. I've been asked to update the document by inserting the corresponding image in front of the name.

Now, if I enter the image manually (using Insert|Image|From File), I'm able to successfully place the PNG image ... so I decided to write a quick VBA Macro to insert the image for me. The following is a sample of the code:

Dim myFile  As String
Selection.SelectCell
Selection.Copy
myFile = _
   Chr(34) & "C:\Documents and Settings\...\Project\Images\" _
   & Left(Selection.Text, Len(Selection.Text) - 2) & Chr(34)

Selection.InlineShapes.AddPicture _
   FileName:=myFile, LinkToFile:=False, SaveWithDocument:=True

Outcomes:

  • Whenever I execute the macro, I get the "Unable to Convert" error dialog, and no image is inserted.
  • I even changed the code to invoke the wdDialogInsertPicture Dialog instead, and it worked just fine.

This is very confusing ... using a manual process, the insert works, but going with an automated solution, the insert doesn't work!

Any ideas or suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栀梦 2024-10-17 17:08:41

我已经尝试了几次宏并且它有效...似乎我无法再重新创建错误。所以,我打算将其标记在“Office VBA 的奥秘”一栏下,并保持原样......这不是一个高优先级的项目,因此我没有必要继续调查。

感谢 AlainJoel Spolsky 的帮助。

I've tried the macro several times and it works ... it seems that I'm no longer able to re-create the error again. So, I'm going to mark this under the "mysteries of Office VBA" column and leave it as is ... this is not a high-priority project, so there is no need for me to continue investigating.

Thanks to Alain and Joel Spolsky for their help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文