OfficeTips Home || VBA Section || General Section || Download Section || Privacy Policy

Reference an ActiveX control on a slide
 

PowerPoint treats everything inserted on the slide as a shape. If the shape is an ActiveX control, you might want to access & manipulate the properties of the control at run-time thru a macro. This example explains how to get a reference to a text box control placed on the slide. The procedure is similar for other controls too.

  • Move to the slide where you want to insert the control.

  • On the View menu, point to Toolbars, and then click Control Toolbox.

  • Click the Text Box button on the Control Toolbox toolbar, and draw the control on your slide.

This text box draw is an object which is placed on the slide. Hence to reference the property we would need to get a reference to this object. Let us see how that is done. One can also get a reference to the object by using the name which PowerPoint will assign to the shape instead of the Index value.
 

' --------------------------------------------------------------------------------
' Copyright ©1999-2016, Shyam Pillai, All Rights Reserved.
' --------------------------------------------------------------------------------
' You are free to use this code within your own applications, add-ins,
' documents etc but you are expressly forbidden from selling or
' otherwise distributing this source code without prior consent.
' This includes both posting free demo projects made from this
' code as well as reproducing the code in text or html format.
' --------------------------------------------------------------------------------

Sub GetTextBoxRef()

'Declare an object variable to store the reference

Dim otxtBox As TextBox ' MS Forms textbox

' Get a reference to the text box object

Set otxtBox = ActivePresentation.Slides(1).Shapes(1).OLEFormat.Object 

'Now manipulate it's properties 

With otxtBox

       .Text = "We can now control the text box"

       .SpecialEffect = fmSpecialEffectRaised 

End With 

End Sub 

 

 


Related Link(s):

PPT2000: How to Add a Shockwave Flash Control to Your Slide

PPT2000: How to Control a Shockwave Flash Object on a Slide


Let us look at some ways to get a reference to the Title shape. First and foremost it is always prudent to check if the slide has a title shape present or not. This saves us the trouble of looking for something that might not be there. The HasTitle property of the Shapes collection on the slide returns a TRUE if the slide has a title.

Thanks to Kedamano  for providing the third method


' --------------------------------------------------------------------------------
' Copyright ©1999-2016, Shyam Pillai, All Rights Reserved.
' --------------------------------------------------------------------------------
' You are free to use this code within your own applications, add-ins,
' documents etc but you are expressly forbidden from selling or
' otherwise distributing this source code without prior consent.
' This includes both posting free demo projects made from this
' code as well as reproducing the code in text or html format.
' --------------------------------------------------------------------------------


' Method 1: Looping thru the placeholders collection
' The title shape is a placeholder which is of the type 
ppPlaceholderCenterTitle
'
or ppPlaceholderTitle these two types never occur on the same slide.

Sub LoopPlaceHolderCollection()
Dim oTitle As Shape
Dim oShp As Shape
With ActivePresentation.Slides(1).Shapes

 If .HasTitle Then
   For Each oShp In .Placeholders
      If oShp.PlaceholderFormat.Type = ppPlaceholderCenterTitle Or _
                            oShp.PlaceholderFormat.Type = ppPlaceholderTitle Then
           Set oTitle = oShp
      End If
   Next oShp
End If

 If Not oTitle Is Nothing Then
        MsgBox "Title of the slide is: " & _
                    oTitle.TextFrame.TextRange.Text, _
                    vbInformation
 Else
        MsgBox "This slide has no Title shape present", _
                    vbExclamation
 End If

End With
End Sub

' Method 2: Using the Title property
' This exploits the fact that if a title shape is present on the slide the Title
' property will return the reference to the title shape. 

Sub UseTitleProperty()
Dim oTitle As Shape
With ActivePresentation.Slides(1).Shapes

   If .HasTitle Then
     Set oTitle = .Title
     MsgBox "Title of the slide is: " & _
                  oTitle.TextFrame.TextRange.Text, _
                  vbInformation
   Else
      MsgBox "This slide has no Title shape present", _
                   vbExclamation
   End If

End With
End Sub

 

' Method 3: Using the PlaceHolders collection
' This exploits the fact that if a title shape is present on the slide it will always
' be the first shape in the placeholders collection.

Sub UsePlaceHolders()
Dim oTitle As Shape
With ActivePresentation.Slides(1).Shapes

   If .HasTitle Then
     Set oTitle = .Placeholders(1)
     MsgBox "Title of the slide is: " & _
                  oTitle.TextFrame.TextRange.Text, _
                  vbInformation
   Else
      MsgBox "This slide has no Title shape present", _
                   vbExclamation
   End If

End With
End Sub

 

 

 


Copyright 1999-2022 (c) Shyam Pillai. All rights reserved.