Can I disable a module?

djl0525

Well-known Member
Joined
Dec 11, 2004
Messages
1,240
I am collecting modules in one workbook so that I can refer to them in one place in the future, but I don't want each module to run every time I open the workbook. I may want some to run, but not all of them. Is there a way to disable a module other than commenting one line at a time (very time consuming)?

Thanks -- DJ
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Put them in standalone modules, rather than ThisWorkbook modules, or in PERSONAL.XLS, or in an add-in,
 
Upvote 0
I like the standalone modules. That's a great idea. I didn't realize they aren't run when you open the workbook, but I looked at some of mine and, yea, that makes sense.

Thanks! -- DJ
 
Upvote 0
Add a toggle switch to your code!

Public myTog As Boolean

Sub myCodeOnOff()

If myTog = True Then
myTog = False
Else
myTog = True
End If
Exit sub


myEventTypeSubCode, like:

If myTog <> True Then Exit Sub

'TheRestOfYourEventCodeHere!
Exit Sub
 
Upvote 0
I like this idea too, but I don't understand it. Like, where do I change the toggle? Can you add some documentation, please?

Thanks -- DJ
 
Upvote 0
djl0525 said:
I like this idea too, but I don't understand it. Like, where do I change the toggle? Can you add some documentation, please?

Thanks -- DJ

The myCodeOnOff() subroutine, when executed, will toggle the running of whatever code is here, as Joe wrote it:

Code:
'TheRestOfYourEventCodeHere!

Only if the myTog variable is True, will that code run.
 
Upvote 0
So I change "true" to "false" in this line when I want to turn it off?

myTog = True

DJ
 
Upvote 0
No!

Do not change the True or False.

The toggle is just that a toggle!
A toggle is something that can be one of two things, like a light switch. If it is on the next time you press the switch it is off, if it is off the next time you press it it is on, over and over again!

The toggle code sets a variable that you can use to test for in an event code Sub.

If you want the event to run automatically flip the toggle by running its Sub or by Calling its Sub. If you want to stop running your code automatically the run the Toggle sub once again and your code will stop running automatically, Untill you run the toggle again!
 
Upvote 0

Forum statistics

Threads
1,224,315
Messages
6,177,843
Members
452,809
Latest member
mar_luna

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