Avatar of hj_daisy
hj_daisy
Flag 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.
Microsoft ApplicationsMicrosoft Word

Avatar of undefined
Last Comment
hj_daisy

8/22/2022 - Mon
GrahamSkan

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

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
hj_daisy

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
hj_daisy

ASKER
Found round about solution
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23