Toggle common tasks

  • Thread starter Thread starter Dallman Ross
  • Start date Start date
D

Dallman Ross

Please forgive me, because I really don't know what I'm doing
yet much with VBA, but . . .

I'm already tired of typing at the top of each VBA module

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

and then turning it back on at the bottom. So I thought
of something like this:


=========================================
Public Sub toggleEvents(evTog As Boolean)
On Error Resume Next

evTog = Abs(evTog - 1)

With Application
.ScreenUpdating = evTog
.EnableEvents = evTog
End With

Debug.Print evTog & " Kilroy was here"

'On Error GoTo 0
End Sub
=========================================


Well, gee, but it says True all the time. What am I doing wrong?
Also, I tried Googling for similar things but so far have come up
empty. Does everybody really just turn that stuff off and back
on with lines of code in every module?

=dman=
 
Please forgive me, because I really don't know what I'm doing
yet much with VBA, but . . .

I'm already tired of typing at the top of each VBA module

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

and then turning it back on at the bottom. So I thought
of something like this:

=========================================
Public Sub toggleEvents(evTog As Boolean)
On Error Resume Next

evTog = Abs(evTog - 1)

With Application
.ScreenUpdating = evTog
.EnableEvents = evTog
End With

Debug.Print evTog & " Kilroy was here"

'On Error GoTo 0
End Sub
=========================================

Well, gee, but it says True all the time. What am I doing wrong?
Also, I tried Googling for similar things but so far have come up
empty. Does everybody really just turn that stuff off and back
on with lines of code in every module?

=dman=

Hi Dallman,

Yes, I type it every time.

You could try...

Public Sub ToggleEvents()
With Application
.ScreenUpdating = Not .ScreenUpdating
.EnableEvents = Not .EnableEvents
End With
End Sub


Ken Johnson
 
Please forgive me, because I really don't know what I'm doing
yet much with VBA, but . . .

I'm already tired of typing at the top of each VBA module

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

and then turning it back on at the bottom. So I thought
of something like this:

=========================================
Public Sub toggleEvents(evTog As Boolean)
On Error Resume Next

evTog = Abs(evTog - 1)

With Application
.ScreenUpdating = evTog
.EnableEvents = evTog
End With

Debug.Print evTog & " Kilroy was here"

'On Error GoTo 0
End Sub
=========================================

Well, gee, but it says True all the time. What am I doing wrong?
Also, I tried Googling for similar things but so far have come up
empty. Does everybody really just turn that stuff off and back
on with lines of code in every module?

=dman=

Or, if you want to stick with what you've done so far, try...

Public Sub toggleEvents(evTog As Boolean)
On Error Resume Next

evTog = Not evTog

With Application
.ScreenUpdating = evTog
.EnableEvents = evTog
End With

Debug.Print evTog & " Kilroy was here"

'On Error GoTo 0
End Sub

Ken Johnson
 
Ken said:
[WRT ScreenUpdating/EnableEvents off/on]
Hi Dallman,
Yes, I type it every time.
:-)

You could try...

Public Sub ToggleEvents()
With Application
.ScreenUpdating = Not .ScreenUpdating
.EnableEvents = Not .EnableEvents
End With
End Sub

Ken, that looks simple enough. Much appreciated, also for your
other answer. I will play some more and see how it works out . . . .

=dman=
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top