I've inserted a large number of form controll buttons (with the text "") into an excel worksheet by copy'n'pasting (from another workbook).
These buttons are connected to this macro (which is located in PERSONAL.XLSB):
Option Explicit
Sub ChangeSomething()
' The button which called the macro.
Dim b As Button
Set b = ActiveSheet.Buttons(Application.Caller)
' Do run the code if the button was not already active.
If b.Text <> "x" Then ' SEEMS TO BE THE PROBLEM
' Do something
' Mark the button as activated.
b.Text = "x"
b.Font.Bold = True
' If the button was already activated, deactivate it.
Else
'Mark the button as deactivated.
b.Text = ""
End If
End Sub
This set up worked properly before. But since copying, I get Runtime Error 1004
"Unable to set the Text property of the Button class".
When handled, the exception seems to be Error 438
"Object Doesn't Support This Property or Method".
The Debugging marks the line:
If b.Text <> "x" Then
What puzzles me is that getting the text property seems to throw the runtime error, but setting the value runs just fine:
b.Text = "x"
The correct Button in the correct Worksheet of the correct Workbook is changed.
As soon as I change the text of the button manually to something other than "", the macro also seems to work.
Unfortunately, the inserted buttons do not appear to be included in the list returned by ActiveSheet.Buttons
, so I can not loop over them to change their values.
I'm not sure if that's appropriate, but I've uploaded here a sample file.