VBA Checkbox buttons

CodesiriuS

New Member
Joined
Dec 18, 2016
Messages
27
Hello - I have a userform with two command buttons and three check boxes -
The first command button gets a file and drops it in a textbox -
Then I have three Check boxes (all formatting related)
My Question is surrounding my command button 2 "Process File" I was hoping the user would select this button and then based on whether the checkbox is checked will run the macros associated with the check boxes selected - I get a error at the application. Run
Does anybody know why this isn't working?

Private Sub CommandButton2_Click()
If CheckBox1.Value = True Then
Application.Run
Else
End If
CheckBox1.Value = False


If CheckBox2.Value = True Then
Application.Run
Else
End If
CheckBox1.Value = False

 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
You'll need to specify the macro to run. For example, let's say that your macro is named "MyMacro"...

Code:
Application.Run "MyMacro"

To include the module, let's say "Module1"...

Code:
Application.Run "Module1.MyMacro"

To include the VBA project, let's say "VBAProjectName"...

Code:
Application.Run "VBAProjectName.Module1.MyMacro"

Hope this helps!
 
Upvote 0
Thanks Domenic I still get an error after adding "module1"
Private Sub CommandButton2_Click()
If CheckBox1.Value = True Then
Application.Run "module1"
Else
End If
CheckBox1.Value = False
 
Upvote 0
In my example, I assumed that the macro is called "MyMacro". So you'll need to replace it with the actual name of your macro. To specify the module that "MyMacro" resides in, let's say it's "Module1", then you would use...

Code:
Application.Run "Module1.MyMacro"

Notice the dot (.) between Module1 and MyMacro. Then, if you want to further specify the workbook that the macro is found, let's say that the VBA project name is "VBAProjectName", you would use...

Code:
Application.Run "VBAProjectName.Module1.MyMacro"

The project name can be found in the Visual Basic Editor (Alt+F11)...

Code:
Tools > VBAProject Properties > General > Project Name

If you haven't given it a name, it will have the default name VBAProject. So if you're going to specify the VBA project, give it a unique name.
 
Upvote 0

Forum statistics

Threads
1,214,657
Messages
6,120,777
Members
448,991
Latest member
Hanakoro

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