开发者

MS Word Macro ... unable to insert PNG

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜