Running a macro from a UserFrom

seleseped

Board Regular
Joined
Feb 1, 2005
Messages
59
Hello,
I am creating a UserForm for the first time and am having a bit of trouble getting a macro to run when an option button is clicked. To avoid writing multiple lines of code to hide various ActiveX controls depending on which option button is clicked, I've written macros to hide various combinations of those controls.

For example (this is in Module1),
Public Sub HideSet1()
fraSet1.Visible = False
lblSet1.Visible = False
OptSet1.Visible = False
OptSet1.Value = False
End Sub

Then, when option button 2 is clicked, I'd like the HideSet1 macro to run. This is the code (in UserForm1) that I've written for that:
Sub Opt2_Click()
Application.Run "HideSet1"
'bunch of other code
End Sub

However, when I run that macro, I get a "Run-time error '424': Object required' error at the first line of the HideSet1 code. I suspect that it may have to do with where I've placed the HideSet1 code or how I've declared the macros (Public vs. Private) or something like that. I've tried various placements and declarations to no avail. Could somebody please help?

Thanking you in advance for your time and expertise.
 
Place the sub HideSet1 in the userform, then simply:

Rich (BB code):
Sub Opt2_Click() 
    HideSet1
    'bunch of other code
End Sub
 
Upvote 0
Where are fraSet1, lblSet1 etc located and where is the sub HideSet1 located?
 
Upvote 0
I apologize for the delayed thank you (I thought I had replied weeks ago). Your correction in my code was exactly what I was looking for and I am now happily moving forward with the project.
 
Upvote 0

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