Solved

Getting shape picture name using Word VBA (2003)

Posted on 2010-11-08
5
1,952 Views
Last Modified: 2012-05-10
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
Comment
Question by:hj_daisy
  • 3
5 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 34091873
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
 

Author Comment

by:hj_daisy
ID: 34151397
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
 

Accepted Solution

by:
hj_daisy earned 0 total points
ID: 36403985
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
 

Author Closing Comment

by:hj_daisy
ID: 36465379
Found round about solution
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question