Results 1 to 12 of 12

Thread: Solved: Tags or Names

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #10

    Another usefull routine when working with Tags

    using Tags is working out great. In the process I have run accorss situations where I can Hide, Modify, or Delete Shapes based on Tag Name and/or Value. One task which was a bit challenging was deleting all shapes on a slide based on Tag name. The main issue is that the shapes position in a typical for i = 1 to shape.tags.count logic will skip some shapes due to dynamic reordering of the shapes as predecessor shapes are deleted. Anyhow, I though I'd post this short usefull snippet in case anyone finds it usefull...

    As you can see the key is to simply to reverse the order (For j = oSld.Shapes.Count To 1 Step -1). I found the solution in a couple of different postings. Problem is the solutions I found did not drill down far enough for a shape with tags implementation.

    In case anyone is wondering the second "for" loop (For i = 1 To oSh.Tags.Count) is to cycle through all tags for a given shape since there is no limit to how many tab/value pairs you can associate with a given shape.

    Sub DeleteAllWithTag_Slide(SlideName As String, tagName As String)
    Dim oSh As Shape
    Dim oSld As Slide
    Dim i As Long
    Dim j As Long
    Dim name, value As String
    Set oSh = Nothing
    Set oSld = Nothing
    Set oSld = ActivePresentation.Slides(SlideName)
    j = oSld.Shapes.Count
    For j = oSld.Shapes.Count To 1 Step -1
        On Error Resume Next
        Set oSh = oSld.Shapes(j)
        For i = 1 To oSh.Tags.Count
            name = oSh.Tags.name(i)
            If LCase(name) = LCase(tagName) Then
                oSh.Delete
           End If
       Next
    Next
    End Sub
    Last edited by Aussiebear; 04-28-2023 at 02:22 AM. Reason: Adjusted the code tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •