Link to home
Start Free TrialLog in
Avatar of hj_daisy
hj_daisyFlag for Afghanistan

asked on

Getting shape picture name using Word VBA (2003)

In a Word 2003 document, I have a shape that I have already inserted a picture into using the Fill Effects option and then selecting an external picture.  Let's say I have created a circle shape and inserted an image called 'Grey background.gif'.

I need the Word VBA code that will tell me the name of the picture inserted into the shape because my macro will change it if it says 'Grey background.gif' but will not change it if it says something else.  I can't store the name of the picture anywhere such as in a document property etc because the user may change it manually and I won't know what they have inserted.

Thanks for your help.
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Inserted shapes only have the file name if they are linked. Otherwise they have a sequential default name assigned.
Sub ShapeNames()
    Dim sh As Shape
    Dim strMsg As String
    
    For Each sh In ActiveDocument.Shapes
        strMsg = "Name: " & sh.Name & ". File: "
        If sh.LinkFormat Is Nothing Then
            strMsg = strMsg & " (Not Linked)"
        Else
            strMsg = strMsg & sh.LinkFormat.SourceFullName
        End If
        MsgBox strMsg
    Next sh
End Sub

Open in new window

Avatar of hj_daisy

ASKER

Hi GrahamSkan

How can I link the file so that your macro will get the filename?  

It's strange that it would show the filename in the dialog box where you select the image to be inserted into the shape yet it doesn't know how to get that information.  

I have attached a document showing the screen that I'm referring to.


Picture-in-shape.doc
ASKER CERTIFIED SOLUTION
Avatar of hj_daisy
hj_daisy
Flag of Afghanistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Found round about solution