Header
PowerPoint tips, hints and tutorials that will change your presentations for ever!

INDEX

 

Jigsaws
Sounds
Video
Custom Shows
vba code
NaviSlides
Games for teachers
Bullets
Triggers
Security
Flash Cards
Multiple Instances
PowerPoint 2007
Mail Merge
Random events
Animation
Hyperlinks
Set spellcheck language


Home buttonTutorial buttonContact buttonProducts button


Powerpoint vba - Using Tags

Tags are a very useful feature and often overlooked by vba programmers.

Tags are like labels that you can attach to a PowerPoint Presentation, Slide or Shape. They can only be "seen" in vba are remain totally invisible to the normal user. Tags have a Name and a Value associated with that name. You can attach many Tags to an object. The tag name and value should be strings. Note case is not considered by tags "thistag" is the same as "ThiStaG". By convention Upper case is usually used.

Add Tags to a Range of Slides

This code adds a tag named "type" to all selected slides and sets the value at "one"

Sub AddTags()
Dim osld As Slide
Dim sTagName As String
Dim sTagValue As String

'change to suit
sTagName = "TYPE"
sTagValue = "ONE"

'check for selection
If ActiveWindow.Selection.Type = ppSelectionNone Then GoTo errhandler

'add tags
For Each osld In ActiveWindow.Selection.SlideRange
osld.Tags.Add sTagName, sTagValue
Next osld
Exit Sub
errhandler:
MsgBox "You need to select slides!"
End Sub

This code does the same for a range of shapes on a slide

Sub AddTags()
Dim oshp As Shape
Dim sTagName As String
Dim sTagValue As String

'change to suit
sTagName = "TYPE"
sTagValue = "TWO"

'check for selection
If ActiveWindow.Selection.Type <> ppSelectionShapes Then GoTo errhandler

'add tags
For Each oshp In ActiveWindow.Selection.ShapeRange
oshp.Tags.Add sTagName, sTagValue
Next oshp
Exit Sub
errhandler:
MsgBox "You need to select shapes!"
End Sub

To use a tag

Hides tagged shapes on slide one

For Each oshp In ActivePresentation.Slides(1).Shapes
If oshp.Tags("TYPE") = "TWO" Then oshp.Visible = False
Next oshp

OR

Hides tagged slides in Presentation

For Each osld In ActivePresentation.Slides
If osld.Tags("TYPE") = "TWO" Then osld.SlideShowTransition.Hidden = True
Next osld

Enumerate the Tags on Shapes for a Given Slide

Sub Show_Tags()

Dim i As Long
Dim oShp As Shape
Dim osld As Slide
Dim strOutput As String

Set osld = ActiveWindow.View.Slide
If osld.Tags.Count > 0 Then
strOutput = strOutput & "Tags on Slide:" & vbCrLf & "++++++++" & vbCrLf

With osld.Tags
For i = 1 To .Count
strOutput = strOutput & "Tag Name =" & .Name(i) & vbTab & "Tag Value =" & .Value(i) & vbCrLf
Next i
strOutput = strOutput & vbCrLf
End With
End If
strOutput = strOutput & "Tags on Shapes:" & vbCrLf & "++++++++++" & vbCrLf
For Each oShp In osld.Shapes
If oShp.Tags.Count > 0 Then
strOutput = strOutput & "Shape Name " & oShp.Name & vbCrLf
With oShp.Tags

For i = 1 To .Count
strOutput = strOutput & "Tag Name =" & .Name(i) & vbTab & "Tag Value =" & .Value(i) & vbCrLf
Next i
strOutput = strOutput & vbCrLf
End With
End If

Next oShp
MsgBox strOutput
End Sub

Use a Function to Read a Tag

Function readtag(oshp As Shape, strTagname As String) As String
readtag = oshp.Tags(strTagname)
End Function

To Use this Function

MsgBox readtag(oshp, "ALT") ' where ALT is the tag name

 

 
 

Back to the Index Page

POWERPOINT BLOG

Articles on your favourite sport

Free Microsoft PowerPoint Advice, help and tutorials, Template Links
This website is sponsored by Technology Trish Ltd
© Technology Trish 2007
Registered in England and Wales No.5780175
PowerPoint® is a registered trademark of the Microsoft Corporation