PDA

View Full Version : [SOLVED:] Selection.InlineShapes.AddPicture - Strange Behavior



Mavila
01-25-2014, 10:30 PM
I'm inserting a picture into a Word document from a variable using:

Selection.InlineShapes.AddPicture (CustomArray(cp, 1))

The array variable works fine, but what I'm finding is that if the array value is a *.gif, the picture is inserted properly as an image. However, it it's a *.jpg, the actual path text is inserted instead - not the picture. Both the gif file and the jpg file are in the same folder, incidentally.

Anyone able to shed some light on this? Thanks for any help!

fumei
01-25-2014, 10:35 PM
Hmmm, that is strange. Can you post your code?

Mavila
01-25-2014, 10:41 PM
Thanks, fumei:


Dim cp As Long
For cp = 0 To UBound(CustomArray())
If CustomArray(cp, 0) = "Cover Page.docx" Then 'There's a match - it's customizable and the data needs to be entered
If ActiveDocument.Bookmarks.Exists(CustomArray(cp, 2)) Then
If CustomArray(cp, 1) Like "*.bmp" Or CustomArray(cp, 1) Like "*.gif" Or CustomArray(cp, 1) Like "*.jpg" Then 'It's the logo
ActiveDocument.Bookmarks(CustomArray(cp, 2)).Range.Select
Selection.InlineShapes.AddPicture (CustomArray(cp, 1))
ActiveDocument.InlineShapes(ActiveDocument.InlineShapes.Count).Range.Select
Selection.InlineShapes.Item(1).LockAspectRatio = msoTrue
Selection.InlineShapes.Item(1).Height = 72
Selection.InlineShapes.Item(1).Width = 144
Else
MsgBox CustomArray(cp, 1)
ActiveDocument.Bookmarks(CustomArray(cp, 2)).Range = CustomArray(cp, 1)
End If
End If
End If
Next

Mavila
01-26-2014, 02:02 AM
Apparently, it makes a difference if it's "*.jpg" versus "*.JPG" - I switched to capital letters and it works. In the test for image extensions, it wasn't recognizing "*.jpg" and therefore entered the test in the "ELSE" part of the test.

fumei
01-26-2014, 07:33 PM
Well, there ya go. It is case sensitive you know. So to cover BOTH jpg and JPG, use

Or UCase(CustomArray(cp, 1)) Like "*.JPG"

that way, jpg (in the array) gets converted to JPG, and actual JPG work as well.