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

 

Some videos you may like

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,406
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!
 

CodesiriuS

New Member
Joined
Dec 18, 2016
Messages
27
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
 

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,406
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,576
Messages
5,596,965
Members
414,114
Latest member
Lost_User21

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
Top