Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2182
  • Last Modified:

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.
0
hj_daisy
Asked:
hj_daisy
  • 3
1 Solution
 
GrahamSkanCommented:
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

0
 
hj_daisyAuthor Commented:
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
0
 
hj_daisyAuthor Commented:
I ended up storing the name of the picture that I inserted into the shape in the web alternative text field and that way I could use vba to look at the information and that told me if there was a picture in there or not.  Bit clunky but it works.  Thanks Graham for assisting with this problem anyway.
0
 
hj_daisyAuthor Commented:
Found round about solution
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now