Sub exampleShapes()
Dim shp As Shape
For Each shp In Me.Shapes
MsgBox TypeName(shp.OLEFormat.Object) & vbTab & shp.OLEFormat.Object.Name
Next
End Sub
Sub Test()
On Error GoTo err2
ActiveSheet.Shapes("Button 1").Select
MsgBox "Button Exists"
Exit Sub
err2:
MsgBox "Button Doesn't Exist"
End Sub
GTO's script is best, however you could use the following if you want to do a process if it exists.
Option Explicit
Sub example()
Dim myButton As Button
Dim wks As Worksheet
For Each wks In ThisWorkbook.Worksheets
Set myButton = Nothing
On Error Resume Next
Set myButton = wks.Buttons("Button 1")
On Error GoTo 0
If Not myButton Is Nothing Then
myButton.Caption = "Here I am!"
myButton.OnAction = "TestSub"
Exit For
End If
Next
End Sub
Sub TestSub()
MsgBox "Hello"
End Sub
GTO, both my script and your latest script will not work in 2010, tested it on my work operating system which says that it is 2002 and they work fine.
Set myButton = wks.Buttons("Button 1")