VBA Powerpoint Selecting text boxes

Thanks to expert Jamie Garroch I created two macros, one to rename all the text boxes on a slide and one to tab though them based on their name. The problem is to use it now I have to have people first run the macro to rename all the text boxes and then have them run the macro to tab through them. I think a better solution is to rewrite the two macros into one so that a user can select the text boxes and run it. Do that that I added some code to add SELECTION to the .ALTERNATIVETEXT property of the selected text boxes. Then the macro runs to rename all the text boxes. Finally it should reselect those boxes that have SELECTION in .ALTERNATIVETEXT. How do I select all the text boxes that have SELECTION in .ALTERNATIVETEXT so I can run the rest of my macro?

Thanks!
Ed MatsuokaPartner/Senior IT SpecialistAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jamie GarrochPowerPoint Consultant & DeveloperCommented:
Thanks for the kind comment Eddie. Why not set a reference to the user selection at the beginning, do your actions and then reselect the original set of shapes when done?

Something like this:
Dim oSel as ShapeRange
Set oSel = ActiveWindow.Selection.ShapeRange
' do your actions
oSel.Select
Set oSel = Nothing

Open in new window

If you want to identify objects by code, it's best to use a mechanism not exposed to users via the PowerPoint UI (because they can break your functionality) and that mechanism is Tags:
' Add a tag to each shape in the user selection
Public Sub AddTagToSelection()
  Dim oShp As Shape
  For Each oShp In ActiveWindow.Selection.ShapeRange
    oShp.Tags.Add "MY_TAG_NAME", "MY_TAG_VALUE"
  Next
End Sub

Open in new window

And to read them back:
' Pass a shape object, a tag name and value and the function returns true if that
' tag exists for the shape
Public Function ShapeHasTag(oShp As Shape, TagName As String, TagValue As String) As Boolean
  Dim counter As Integer
  
  For counter = 1 To oShp.Tags.Count
    If oShp.Tags.Name(counter) = TagName Then _
      If oShp.Tags.Value(counter) = TagValue Then ShapeHasTag = True: Exit Function
  Next
End Function

Open in new window

You need to take care of groups but this works independently of user edits.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ed MatsuokaPartner/Senior IT SpecialistAuthor Commented:
It's great to have this site where people can go to get answers and a quick response. I use it almost exclusively since I switched over from my days writing VB6 programs to writing macros for Excel, Powerpoint and Word. I will play around with this code when I get a chance. As for why I don't set a reference to the selected objects and then return to those objects, since I wrote my macro to change the names of all text boxes on a slide, it has to select each text box so of course the text boxes my users selected get unselected. The ideal solution of course would be if I could rename all the text boxes on a slide without having to select them but I didn't think that was possible.
0
Jamie GarrochPowerPoint Consultant & DeveloperCommented:
Eddie, you do need to select objects to perform certain method operations such as grouping/ungrouping, aligning etc. but you don't need to when changing properties such as name, tags, alt text, position, size, text content etc. You don't even need the slide on which the shapes appear to be in view. So you can do this without the shape in view or selected:

' Reference the shape by its index
ActivePresentation.Slides(1).Shapes(1).Name = "my shape"
' Reference the shape by its name
ActivePresentation.Slides(1).Shapes("Rectangle 1").Name = "my shape"

Open in new window


But, because your macro starts with a user selection, you "could' store that selection as per my code example above and then do whatever you want, unselecting and selecting various shapes, before restoring the selection at the end of your code.

Good luck!
0
Ed MatsuokaPartner/Senior IT SpecialistAuthor Commented:
Quick response time, perfect answer.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.