Consulting

Results 1 to 12 of 12

Thread: Solved: Tags or Names

  1. #1

    Solved: Tags or Names

    I have read some discussion threads advocating “Names” and other threads advocating “Tags”.

    Does anyone have an opinion whether one approach has any significant advantage(s) over the other?

    Are there specific scenarios which would tend to dictate the use of one approach over the other?


    Name Examples:
    -----------------------
    ActivePresentation.Slides(1).Name = "CBRSlide1"
    For i = 1 To 9
        tickName = "tickline" & I
        ActivePresentation.Slides(x).Shapes(tickName).Delete
            Next i

    Tag Name Examples:
    --------------------
    Sub AssignTagValue()
     Dim strTagValue As String
     Dim strTagExists As String
     strTagValue = frmCBR.txtTag.Text
    ActivePresentation.Slides(1).Tags.Add "CustomerName", strTagValue
    strTabExists = ActivePresentation.Slides(1).Tags("CustomerName")
    End Sub
    ActivePresentation.Slides(4).Tags.Add Name:="IncludeIn", Value:= "ABD" 
    
    strTabExists = ActivePresentation.Slides(1).Tags("CustomerName")
    Thanks for any pearls of wisdom ...
    Last edited by Aussiebear; 04-28-2023 at 02:18 AM. Reason: Adjusted the code tags

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    With tags you can do things which won't work with shape names.
    Also tags are invisible to the normal user
    eg

    Several shapes on one slide can have the same tags:
    so all shapes on slide z with tag "xyz" make visible etc You cannot reuse shape names on one slide

    Shapes can have several tags so you can search for several properties at once:

    You can also find shapes with eg tags "fill" = "red" and add further tags the basis of a selection database.

    Hope that makes some sense
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    First of all... I hope folks on the discussion board appreciate members like John for sharing their expertise as much as I do. Thank you John.

    That being said, sounds like Tags are a good way to go. Interesting that virtually all the code snippets I have run across utilize Names when Tagging seems like an excellent and flexible approach.

    Thanks again John.

  4. #4
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    Heh... learn something new every day! This little bit of knowledge makes me want to re-write some of my own code. I didn't know about TAGS! Thanks for posting this.
    Office 2010, Windows 7
    goal: to learn the most efficient way

  5. #5
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    For the record this is how I had to learn. Iwrote a vba program for a company that wanted to have a finance product "suggester". You clicked a "I am 18" and "unnmarried" etc buttons and a variety of suggested options went green.

    The code looked something like (not real code!!)

    If shape.name ="x" then fill =green
    If shape.name = "y" then fill = green
    If shape.name = "z" then .... etc

    I would now maybe use a select case statement but its still lengthy compared to

    If oshp.Tags("18unmarried")="yes" then oshp.Fill etc
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  6. #6
    Your welcome Trippy. Of couse I, like you, am the benefactor of picking up some pearls of wisdom form reading other developer's posts. Since I am new to powerpoint development and just now starting to write my code base I wanted to find the best way to get a handle on and manipulate objects.

    Thank you John for the post(s).

  7. #7

    Handy Piece of Code

    In Case anyone is interested, I thought I'd share a piece of code I cobbled together from other examples to fit my needs. I found it a bit overwhelming when you start working with tags which can exist at different levels and multiple time per slide and/or shape. Anyhow, this code will iterate through the current slide and display the Name and Value for each tag. Anyone else with any pearls of wisdom or useful "Tag" snippets please share...


    Sub ViewAllTags()
    Dim oSh As Shape
    Set oSh = Nothing
    Dim sName As String
    Dim lCurrSlide As Long
    lCurrSlide = ActiveWindow.Selection.SlideRange.SlideIndex
    'Slide Level Tag Iteration
    With Application.ActivePresentation.Slides(lCurrSlide).Tags
        For i = 1 To .Count
            MsgBox "Slide Tag #" & i & ": Name = " & .Name(i) _
            & Chr$(13) & "Tag #" & i & ": Value = " & .Value(i)
        Next
    End With
    'Shape Level Tag Iteration
    For Each oSh In Application.ActivePresentation.Slides(lCurrSlide).Shapes
        On Error Resume Next
        For j = 1 To oSh.Tags.Count
            oSh.Select 'Used only for viewing purposes - can delete
            MsgBox "Shape Tag Name #" & j & ": Name = " & oSh.Tags.Name(j) _
            & Chr$(13) & "Tag #" & j & ": Value = " & oSh.Tags.Value(j)
        Next
    Next
    End Sub
    Also, Below is a pretty cool piece of code which started out as a thermometer example. I altered the code for my purposes and enhanced it to use Tags instead of names. The code accepts x as a percentage complete parameter to draw the progress bar. Anyone have any suggestion for me to improve the code feel free to help me improve my code base. The nice thing about the tags implementation is that I used "Progress" as the name for all related shapes. The unique property is the value. This makes it much easier to do things like move or delete the Progress Bar. Enjoy..


    Sub AddOneBar(x As Long)
    Dim dblLeft As Double
    Dim dblTop As Double
    Dim dblheight As Double
    Dim dblNetWidth As Double
    Dim oSh As Shape
    Dim oSh2 As Shape
    Dim oLine As Shape
    Dim i As Double
    Dim slideName As String
    slideName = ActiveWindow.Selection.SlideRange.Name
    ' This determines how far in from left the progress bar will start:
    dblLeft = 10
    ' This determines how high (in points) the progress bar will be:
    dblheight = 25
    ' This puts the progress bar right against the bottom of the slide, no matter what its height
    dblTop = ActivePresentation.PageSetup.SlideHeight - dblheight - 25
    'Net Width of ProgressBar
    dblNetWidth = ActivePresentation.PageSetup.SlideWidth - dblLeft - 10
    Set oSh = ActivePresentation.Slides(slideName).Shapes.AddShape(msoShapeRectangle, _
    dblLeft, _
    dblTop, _
    ((x / 100) * dblNetWidth), _
    dblheight)
    oSh.Fill.ForeColor.RGB = RGB(0, 255, 0)
    oSh.Fill.Visible = msoTrue
    oSh.Tags.Add "Progress", "Area"
    Set oSh2 = ActivePresentation.Slides(slideName).Shapes.AddShape(msoShapeRectangle, _
    dblLeft, _
    dblTop, _
    dblNetWidth, _
    dblheight)
    oSh2.Line.Weight = 3
    oSh2.Line.ForeColor.RGB = RGB(0, 0, 0)
    oSh2.Line.Visible = msoTrue
    oSh2.Tags.Add "Progress", "Outline"
    'Add Tick Mark
    i = 0
    For i = 1 To 9
        Set oLine = ActivePresentation.Slides(slideName).Shapes.AddLine( _
        (i * 10 / 100 * dblNetWidth) + dblLeft, _
        dblTop, (i * 10 / 100 * dblNetWidth) + dblLeft, dblTop + 10)
        oLine.Line.Weight = 2
        Works oLine.Tags.Add "Progress", "tickline" & I
        oLine.Line.Visible = msoTrue
    Next i
    End Sub
    Edited 12-Sep-07 by geekgirlau. Reason: insert VBA tags
    Last edited by Aussiebear; 04-28-2023 at 02:21 AM. Reason: Adjusted the code tags

  8. #8
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    Thanks for sharing DumbPuppy. Please make sure you use the vba tags when posting code - just select the code text, then click on the "VBA" button.

  9. #9
    Will do. Thanks for pointing that out ...

  10. #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

  11. #11
    MS Excel MVP VBAX Mentor Andy Pope's Avatar
    Joined
    May 2004
    Location
    Essex, England
    Posts
    344
    Location
    Hi John,

    I recently became aware of the Tags property in PPT and I can see their potential for helping me doing automated report production.

    I'm currently writing my own Tag manager but I was wondering if you knew of any free addins or utilities to manager tags?


    Mods: If my question is OT for this thread please move
    Cheers
    Andy

  12. #12
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    We don't have any Andy. We do have a simple homegrown add in for adding tags to either a selected shape or a range of shapes and a similar one for tagging slides but its pretty basic just based on
    Dim oShpR As ShapeRange'or sliderange
    Set oShpR = ActiveWindow.Selection.ShapeRange 'or sliderange
    For i = 1 To oShpR.Count
        Set oshp = oShpR(i)
        oshp.Tags.Add strTName, strTVal
    Next
    I'd be interested in anything you produce though!
    Last edited by Aussiebear; 04-28-2023 at 02:23 AM. Reason: Adjusted the code tags
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Posting Permissions

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