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

x
?
Solved

how do I get the index of a particular shape in a collection of activedocument.shapes MS Word VBA

Posted on 2013-01-29
4
Medium Priority
?
727 Views
Last Modified: 2013-01-29
how do I get the index of a particular shape in a collection of activedocument.shapes MS Word VBA
0
Comment
Question by:Dov_B
  • 2
  • 2
4 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 38830503
How do you define the particular shape, i.e. what information about the shape are you starting with?
0
 

Author Comment

by:Dov_B
ID: 38830524
well in  the solution you gave me an hour ago
you wrote the following code
Sub AddSmallTransparentCaption()
    Dim sh As Shape
    Dim tb As Shape
    Dim s As Integer

    s = 1
    
    Set sh = ActiveDocument.Shapes(s)
    sh.Select
    Selection.InsertCaption "Figure", , , wdCaptionPositionBelow
    
    Set tb = ActiveDocument.Shapes(s + 1)
    With tb
        .TextFrame.TextRange.Font.Size = 6
        .Fill.Transparency = 1
        .TextFrame.AutoSize = True 'doesn't seem to work
    End With
End Sub

Open in new window

so I wanted to know how I could add captions to pre existing shapes in my old document by selecting them and running a macro but I won't Be able to reference the caption because I won't know its index in the collection
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 2000 total points
ID: 38830568
I used the Index, because I didn't know about your situation.

If you were wanting to incorporate the code into a larger macro that, say, loops through several shapes, then the index would be useful. In fact, the InsertCaption method only works with the Selection, so it is necessary to ensure that the Shape is selected.

If you are starting with the shape already selected,  omit lines 8 & 9. When the caption is created, it is automatically selected, so you just need to use the first ShapeRange Object.
Sub AddSmallTransparentCaption()
    Dim tb As Shape
    
    Selection.InsertCaption "Figure", , , wdCaptionPositionBelow
    
    Set tb = Selection.ShapeRange(1)
    With tb
        .TextFrame.TextRange.Font.Size = 6
        .Fill.Transparency = 1
        .TextFrame.AutoSize = True 'doesn't seem to work
    End With
    tb.Width = 30
    tb.Height = 10
End Sub

Open in new window

0
 

Author Closing Comment

by:Dov_B
ID: 38830587
Dear GrahamSkan I am a teacher and an amateur self taught programmer I am in the middle of making a library of free material for elementary students with learning disabilities. It is only possible because of the many answers you have given me! May you be blessed with everything GOOD!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
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 …
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

824 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