PDA

View Full Version : Solved: Tags or Names



dumbpuppy
09-06-2007, 03:00 PM
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 ...

John Wilson
09-06-2007, 11:53 PM
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

dumbpuppy
09-07-2007, 08:37 AM
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.

TrippyTom
09-07-2007, 08:52 AM
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.

John Wilson
09-07-2007, 11:29 AM
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

dumbpuppy
09-07-2007, 12:14 PM
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).

dumbpuppy
09-11-2007, 03:22 PM
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

geekgirlau
09-11-2007, 08:22 PM
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.

dumbpuppy
09-12-2007, 06:50 AM
Will do. Thanks for pointing that out ...
:doh:

dumbpuppy
09-27-2007, 02:38 PM
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

Andy Pope
09-28-2007, 01:22 AM
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

John Wilson
09-28-2007, 02:39 AM
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!