LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default cancel message while sub running

sorry, i guess i didnt' make my question/comment clear.

When i pasted the code (with the DoEvents uncomment) in my graph_click sub,
then run the program. The userform2 appears but i am unable to click the
Cancel button. When i click on the cancel button, the program still runs
though my sub and at the end then it will show "user cancelled", but the
program already completed so the point of having the cancel button is lost
=(.

so i created a userform2 and pasted the form code as in Patrick's response.

then i pasted the code form userform 1 into my Graph_button_click sub (but
was unable to hit the cancel button on the userform2, explained above) . My
sub Graph_button_click is pretty long so i won't paste it into this message.
Below is an idea of what i have in the sub. I guess i don't know how to use
the code from step 2 (see Patrick Molloy message) with my graph_button_click
code. Please advise.

sub Graph_button_click
obtain data
do calculation
create graphs
end sub

2)
Option Explicit
Private Sub CommandButton1_Click()
UserForm2.Show vbModeless
Dim i As Long
For i = 1 To 100000
UserForm2.Label2.Caption = i
DoEvents
If UserForm2.bCancelled Then Exit For
Next
If UserForm2.bCancelled Then
MsgBox "user cancelled"
else
MsgBox "finished normally"
End If
Unload UserForm2
End Sub


thanks for your help!
--
Learning


"smartin" wrote:

' DoEvents - is there where i add in my code - obtain data,


DoEvents is a one word instruction that tells VBA to pause execution and
process Events -- such as a user clicking a "Cancel" button or redrawing
a label caption. Once events are processed, execution resumes. As such,
DoEvents is important here and you should uncomment it. Without it your
loop will fly around at the speed of light and not give Windows a chance
to process the Click event.

In practice you will not notice the "pause", but your program should be
more responsive to the clicks you intend to handle.

tracktraining wrote:
I tried your code and incorporate it into my code and it didn't work. when
userform2 appears, i can unable to click cancel - my code runs as is.

2)
Option Explicit
Private Sub CommandButton1_Click()
UserForm2.Show vbModeless
Dim i As Long
For i = 1 To 100000
UserForm2.Label2.Caption = i
' DoEvents - is there where i add in my code - obtain data,
calculation, create graphs (call other functions/subs)?
If UserForm2.bCancelled Then Exit For
Next
If UserForm2.bCancelled Then
MsgBox "user cancelled"
else
MsgBox "finished normally"
End If
Unload UserForm2
End Sub




 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
cancel Update message? Bob Excel Discussion (Misc queries) 3 June 10th 09 12:53 PM
Can't get Cancel to work in message box * Kenneth * Excel Discussion (Misc queries) 1 March 30th 06 08:10 PM
message box without ok or cancel button Subash Excel Discussion (Misc queries) 1 October 18th 05 10:38 AM
How to CANCEL file SAVE PROMPT when MACRO is running? Stuart Macro Muppet Excel Discussion (Misc queries) 3 August 11th 05 12:26 PM
Cancel Message Howard Excel Discussion (Misc queries) 1 December 21st 04 04:31 PM


All times are GMT +1. The time now is 06:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"