Article ID: 161717
Article Last Modified on 10/11/2006
Sub HowMany()
Const StandardMessage As String = "Please select a slide or a" _
& " shape and run the macro again."
' Define a selection object.
Dim TheSelection As PowerPoint.Selection
' String used to create the message box.
Dim Message As String
Dim NumberOfObjects As Long
' Assign the TheSelection to the current selection.
Set TheSelection = ActiveWindow.Selection
' Determine the type of selection.
Select Case TheSelection.Type
' See whether a selection was made.
Case ppSelctionNone
Message = "You don't have anything selected. " _
& StandardMessage
' See whether a slide is selected.
Case ppSelectionSlides
' Get the number of slides selected.
NumberOfObjects = TheSelection.SlideRange.Count
If NumberOfObjects = 1 Then
Message = "You have one slide selected."
Else
Message = "You have " & NumberOfObjects _
& " slides selected."
End If
Case ppSelectionShapes
' Get the number of shapes selected.
NumberOfObjects = TheSelection.ShapeRange.Count
If NumberOfObjects = 1 Then
Message = "You have one shape selected."
Else
Message = "You have " & NumberOfObjects _
& " shapes selected."
End If
Case ppSelectionText
Message = "You have text selected. " & StandardMessage
Case Else
MsgBox "Do not recognize your selection.", vbCritical
End
End Select
' Display the message box.
MsgBox Message, vbInformation
End Sub
161390 PPT: Sample Code to Display the Selection Type
176476 OFF: Office Assistant Not Answering Visual Basic Questions
163435 VBA: Programming Resources for Visual Basic for Applications
Additional query words: 97 8.00 kbmacro ppt8 vba vbe 98 macppt
Keywords: kbhowto kbmacro kbprogramming kbdtacode kbcode KB161717