Solved

Getting shape picture name using Word VBA (2003)

Posted on 2010-11-08
5
2,075 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

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

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…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
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…
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …
Suggested Courses

635 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