PC Review


Reply
Thread Tools Rate Thread

Disable selective events

 
 
Patrick C. Simonds
Guest
Posts: n/a
 
      7th Oct 2008
In the code below I use Application.EnableEvents = False to prevent the
showing of UserForm1 while the code is running. The problem is that it
prevents all events from happening. Is there any way to prevent UserForm1
from showing while still allowing other events to happen?



Private Sub CommandButton1_Click()
Unload End_Of_Month_Disposal
Application.EnableEvents = False
Application.ScreenUpdating = False

ActiveWorkbook.Worksheets("2009 Training").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("2009 Training").Sort.SortFields.Add
Key:=Range( _
"A3:A5000"), SortOn:=xlSortOnValues, Order:=xlAscending,
DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("2009 Training").Sort
.SetRange Range("A2:N5000")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

Range("B2").Select

Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub

 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      7th Oct 2008
Use a global boolean, set that when you want and react according to that
boolean.

--
__________________________________
HTH

Bob

"Patrick C. Simonds" <(E-Mail Removed)> wrote in message
news:e$(E-Mail Removed)...
> In the code below I use Application.EnableEvents = False to prevent the
> showing of UserForm1 while the code is running. The problem is that it
> prevents all events from happening. Is there any way to prevent UserForm1
> from showing while still allowing other events to happen?
>
>
>
> Private Sub CommandButton1_Click()
> Unload End_Of_Month_Disposal
> Application.EnableEvents = False
> Application.ScreenUpdating = False
>
> ActiveWorkbook.Worksheets("2009 Training").Sort.SortFields.Clear
> ActiveWorkbook.Worksheets("2009 Training").Sort.SortFields.Add
> Key:=Range( _
> "A3:A5000"), SortOn:=xlSortOnValues, Order:=xlAscending,
> DataOption:= _
> xlSortNormal
> With ActiveWorkbook.Worksheets("2009 Training").Sort
> .SetRange Range("A2:N5000")
> .Header = xlYes
> .MatchCase = False
> .Orientation = xlTopToBottom
> .SortMethod = xlPinYin
> .Apply
> End With
>
> Range("B2").Select
>
> Application.EnableEvents = True
> Application.ScreenUpdating = True
> End Sub



 
Reply With Quote
 
john
Guest
Posts: n/a
 
      7th Oct 2008
as an idea, what about placing the unload End_Of_Month_Disposal statement at
the end of your procedure and then add at start of each event you want to be
ignored
the following line:

If End_Of_Month_Disposal.Visible = True Then Exit Sub

not tested but something along those lines may be worth a try.

Private Sub CommandButton1_Click()

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

With ActiveWorkbook.Worksheets("2009 Training")
.Sort.SortFields.Clear
.Sort.SortFields.Add Key:=Range("A3:A5000"), _
SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal

With .Sort
.SetRange Range("A2:N5000")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

.Range("B2").Select
End With

With Application
'.EnableEvents = True
.ScreenUpdating = True
End With

Unload End_Of_Month_Disposal

End Sub

--
jb


"Patrick C. Simonds" wrote:

> In the code below I use Application.EnableEvents = False to prevent the
> showing of UserForm1 while the code is running. The problem is that it
> prevents all events from happening. Is there any way to prevent UserForm1
> from showing while still allowing other events to happen?
>
>
>
> Private Sub CommandButton1_Click()
> Unload End_Of_Month_Disposal
> Application.EnableEvents = False
> Application.ScreenUpdating = False
>
> ActiveWorkbook.Worksheets("2009 Training").Sort.SortFields.Clear
> ActiveWorkbook.Worksheets("2009 Training").Sort.SortFields.Add
> Key:=Range( _
> "A3:A5000"), SortOn:=xlSortOnValues, Order:=xlAscending,
> DataOption:= _
> xlSortNormal
> With ActiveWorkbook.Worksheets("2009 Training").Sort
> .SetRange Range("A2:N5000")
> .Header = xlYes
> .MatchCase = False
> .Orientation = xlTopToBottom
> .SortMethod = xlPinYin
> .Apply
> End With
>
> Range("B2").Select
>
> Application.EnableEvents = True
> Application.ScreenUpdating = True
> End Sub
>
>

 
Reply With Quote
 
Patrick C. Simonds
Guest
Posts: n/a
 
      8th Oct 2008
I have to admit I have no idea of how to do that.



"Bob Phillips" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Use a global boolean, set that when you want and react according to that
> boolean.
>
> --
> __________________________________
> HTH
>
> Bob
>
> "Patrick C. Simonds" <(E-Mail Removed)> wrote in message
> news:e$(E-Mail Removed)...
>> In the code below I use Application.EnableEvents = False to prevent the
>> showing of UserForm1 while the code is running. The problem is that it
>> prevents all events from happening. Is there any way to prevent UserForm1
>> from showing while still allowing other events to happen?
>>
>>
>>
>> Private Sub CommandButton1_Click()
>> Unload End_Of_Month_Disposal
>> Application.EnableEvents = False
>> Application.ScreenUpdating = False
>>
>> ActiveWorkbook.Worksheets("2009 Training").Sort.SortFields.Clear
>> ActiveWorkbook.Worksheets("2009 Training").Sort.SortFields.Add
>> Key:=Range( _
>> "A3:A5000"), SortOn:=xlSortOnValues, Order:=xlAscending,
>> DataOption:= _
>> xlSortNormal
>> With ActiveWorkbook.Worksheets("2009 Training").Sort
>> .SetRange Range("A2:N5000")
>> .Header = xlYes
>> .MatchCase = False
>> .Orientation = xlTopToBottom
>> .SortMethod = xlPinYin
>> .Apply
>> End With
>>
>> Range("B2").Select
>>
>> Application.EnableEvents = True
>> Application.ScreenUpdating = True
>> End Sub

>
>


 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      9th Oct 2008
Create a global variable in a standard module

Global fSuppressEvents As Boolean

and then in your code test it before showing the form say

If Not fSuppressEvents Then Show Userform1

and then set/reset that flag in you main code

'do something
Set fSuppressEvents =True
'do some more
fSuppressEvents = False

'etc.

--
__________________________________
HTH

Bob

"Patrick C. Simonds" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have to admit I have no idea of how to do that.
>
>
>
> "Bob Phillips" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> Use a global boolean, set that when you want and react according to that
>> boolean.
>>
>> --
>> __________________________________
>> HTH
>>
>> Bob
>>
>> "Patrick C. Simonds" <(E-Mail Removed)> wrote in message
>> news:e$(E-Mail Removed)...
>>> In the code below I use Application.EnableEvents = False to prevent the
>>> showing of UserForm1 while the code is running. The problem is that it
>>> prevents all events from happening. Is there any way to prevent
>>> UserForm1 from showing while still allowing other events to happen?
>>>
>>>
>>>
>>> Private Sub CommandButton1_Click()
>>> Unload End_Of_Month_Disposal
>>> Application.EnableEvents = False
>>> Application.ScreenUpdating = False
>>>
>>> ActiveWorkbook.Worksheets("2009 Training").Sort.SortFields.Clear
>>> ActiveWorkbook.Worksheets("2009 Training").Sort.SortFields.Add
>>> Key:=Range( _
>>> "A3:A5000"), SortOn:=xlSortOnValues, Order:=xlAscending,
>>> DataOption:= _
>>> xlSortNormal
>>> With ActiveWorkbook.Worksheets("2009 Training").Sort
>>> .SetRange Range("A2:N5000")
>>> .Header = xlYes
>>> .MatchCase = False
>>> .Orientation = xlTopToBottom
>>> .SortMethod = xlPinYin
>>> .Apply
>>> End With
>>>
>>> Range("B2").Select
>>>
>>> Application.EnableEvents = True
>>> Application.ScreenUpdating = True
>>> End Sub

>>
>>

>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disable Events Imran Ghani Microsoft Access VBA Modules 2 7th May 2009 03:31 PM
RE: Disable Events Mr. B Microsoft Access VBA Modules 0 6th May 2009 03:14 PM
Events won't Disable! =?Utf-8?B?cm9hZGtpbGw=?= Microsoft Excel Misc 3 26th Apr 2006 07:24 PM
Is it possible to disable events? ORC Microsoft C# .NET 8 5th Dec 2004 09:35 AM
Disable selective boot? Tom Markley Windows XP Setup 1 18th Nov 2003 07:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:18 PM.