MS Excel VBA Macro Button Errorq

OilEconomist

Active Member
Joined
Dec 26, 2016
Messages
421
Office Version
  1. 2019
Platform
  1. Windows
Hello and thanks in advance. How would I have have an error message pop up if a Macro Button is not selected as depending on which button is selected, it uses this text within it to execute different parts of the sub/macro.

This is what I have so far, but I still get the error "Run-time error '1004': Unable to get the Buttons property of the Worksheet class!

VBA Code:
Option Explicit
Sub MacroTextButton()

    Dim MacroText As String
    Dim ShtNm As String
    
    ShtNm = "Sheet1"
    
    
    With Sheets(ShtNm)
        MacroText = .Buttons(Application.Caller).Caption
        If MacroText = "" Then
            MsgBox "You did not select a Macro Button! This Macro/Sub will be exited! Please select a button the next time"
            Exit Sub
        End If
    End With


End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Are you using a Form control button, rather than a shape or an ActiveX button?
 
Upvote 0

Forum statistics

Threads
1,214,967
Messages
6,122,503
Members
449,090
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top