Solved

Getting shape picture name using Word VBA (2003)

Posted on 2010-11-08
5
1,913 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
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…
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now