Reputation: 341
I don't understand why this VBA code returns run-time error 438:
With Worksheets("DATA1").Shapes("CommandButton4")
.TextFrame.Characters.Text = "In Stock"
End With
I need to change the caption of the button.
The code is in Private Sub Workbook_Open().
Upvotes: 0
Views: 1671
Reputation: 42236
I asked you about the button type, but no answer. So, I will provide solutions for both types (Form or ActiveX). Please, check the next pieces of code:
In case of an ActiveX button (more probable, according to its name):
Sub changeActiveXButtonCaption()
Dim bt As MSForms.CommandButton
Set bt = ActiveSheet.OLEObjects("CommandButton4").Object
bt.Caption = "In Stock"
End Sub
In case of a Form button, please check/use the next code:
Sub changeFormButtonCaption()
Dim bt As Button
Set bt = ActiveSheet.Buttons("CommandButton4")
bt.Caption = "In Stock"
End Sub
Any of the above controls do not have a TextFrame
property. Such a property, usually, belongs to a shape. Is your, so named, "CommandButton4" button a shape?
Upvotes: 2