0

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().

1
  • What type of a Control (Button) are you talking about? Is it a Frame or an ActiveX control? Commented Jan 15, 2022 at 15:14

1 Answer 1

2

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?

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry, I was out for some errands. I tried your first solution and it works great. Thank you very much for the awesome help. Really appreciated FaneDuru!
@Dolphin975 This means that the button in discussion is of ActiveX type...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.