0
votes

I've got a macro that searches through all the shapes in a slide and hides the shapes that match certain names. My shapes collection includes a mixture of standard shapes and CommandButtons.

The Command Buttons are having their "Visible" property set to "False" in the properties window, and they aren't visible in the powerpoint edit screen, but they remain visible in the Slide Show view. This issue doesn't occur when I bypass the shape variable (sh.Visible) and refer to the command button directly (startB.Visible). See below:

For Each sh In ActivePresentation.Slides(1).Shapes
    If sh.Name = "startB" Then
        sh.Visible = False
    End If
Next
2

2 Answers

0
votes

When looping through shapes, form control name needs to be checked against the object. I added a first If statement to check the type of shape. Then, the second If will access OLEFormat Object Name.

If sh.Type = msoOLEControlObject Then
    If sh.OLEFormat.Object.Name = "startB" Then
        sh.Visible = False        
    End If
End If
0
votes

I'm assuming it's because the shape is just a component of the Command Button. As a work around, I've got this, though I'm not 100% confident in why this happens:

If sh.Name = "startB" Then
    sh.OLEFormat.Object.Visible = False
End If

Which works fine. I'm a bit lost here because I'm used to Excel where I could refer directly to things as OLEObject.Object, but even though you are still referring to OLEObjects, OLEFormat seems a little different. Just having some issues wrapping my head around it.