You are on page 1of 4

Sub GetCurrentSlideNumber

()
Dim lCurrentView As Long
' Get the current view type.
lCurrentView = ActiveWindow.ViewType
' Make sure that PowerPoint is in Slide view.
' ActiveWindow.Selection.SlideRange.SlideNumber produces an error if
' you are using any other view.
If lCurrentView = ppViewSlide Then
' Display the slide number.
MsgBox "You are on slide: " & _
ActiveWindow.Selection.SlideRange.SlideNumber, vbInformation
Else
' PowerPoint is not in slide view.
MsgBox "You must be in slide view to run this macro.", _
vbInformation
End If
End Sub
################################################################################
#####################
Sub NameShape()
'used to name shapes
'select the shape by clicking on it then go to macros and and then run this code
!!!!
'you can then use that name in VBA to reference that object. lot easier than try
ing to guess at "rectangle 2" or what index a object is.
Dim Name$
On Error GoTo AbortNameShape
If ActiveWindow.Selection.ShapeRange.Count = 0 Then
MsgBox "No Shapes Selected"
Exit Sub
End If
Name$ = ActiveWindow.Selection.ShapeRange(1).Name
Name$ = InputBox$("Give this shape a name", "Shape Name", Name$)
If Name$ <> "" Then
ActiveWindow.Selection.ShapeRange(1).Name = Name$
End If

Exit Sub

AbortNameShape:
MsgBox Err.Description

End Sub
################################################################################
#####################
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 ma
ny 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
################################################################################
#####################
LOAD PICTURE
Dim sld As Slide
Set sld = ActivePresentation.Slides _
(ActivePresentation.SlideShowWindow.View _
.CurrentShowPosition)
Set shp = sld.Shapes(1)
With shp
sld.Shapes.AddPicture(FileName:="<picturePath/url>", LinkToFile:=msoFalse, S
aveWithDocument:=msoTrue, Left:=.Left, Top:=.Top, Width:=.Width, Height:=.Height
).IncrementRotation 276#
.Delete
End With
################################################################################
#####################