Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default How to stop macro with cancel button

Hi !
When I click on form1 (execute button), I close form1 and open a form2 which
indicate a process bar and there is a Cancel button to stop the macro. When I
click on it, the macro continue to run. Is there a way to stop the macro?
Thanks!!
Alex

'Userform1:
Private Sub CreateReport_Click()
UserForm1.Hide
UserForm2.Show
End
End Sub
'Userform2:
Private Sub UserForm_Activate()
Call MainMacro
Unload UserForm2
End Sub
Private Sub CommandButtonCancel_Click()
End 'doesn't work
End Sub
--
Alex St-Pierre
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default How to stop macro with cancel button

You can try adding DoEvents which interupts the existing execution to run
code that has been generated by an event such as clicking on a button. I
assume that you have a loop in your main macro that takes some time to
execute. DoEvents will go in there...
--
HTH...

Jim Thomlinson


"Alex St-Pierre" wrote:

Hi !
When I click on form1 (execute button), I close form1 and open a form2 which
indicate a process bar and there is a Cancel button to stop the macro. When I
click on it, the macro continue to run. Is there a way to stop the macro?
Thanks!!
Alex

'Userform1:
Private Sub CreateReport_Click()
UserForm1.Hide
UserForm2.Show
End
End Sub
'Userform2:
Private Sub UserForm_Activate()
Call MainMacro
Unload UserForm2
End Sub
Private Sub CommandButtonCancel_Click()
End 'doesn't work
End Sub
--
Alex St-Pierre

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default How to stop macro with cancel button

Your code needs to give the form button press the chance to get a look in,
issuing DoEvents throughout the code that updates the progress bar. Beyond
that, we would need to see the code.

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Alex St-Pierre" wrote in message
...
Hi !
When I click on form1 (execute button), I close form1 and open a form2
which
indicate a process bar and there is a Cancel button to stop the macro.
When I
click on it, the macro continue to run. Is there a way to stop the macro?
Thanks!!
Alex

'Userform1:
Private Sub CreateReport_Click()
UserForm1.Hide
UserForm2.Show
End
End Sub
'Userform2:
Private Sub UserForm_Activate()
Call MainMacro
Unload UserForm2
End Sub
Private Sub CommandButtonCancel_Click()
End 'doesn't work
End Sub
--
Alex St-Pierre



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default How to stop macro with cancel button

try typing CNTL-Break from both VBA and excel to stop the code. then look
for errors that may keep the code in a loop.

"Bob Phillips" wrote:

Your code needs to give the form button press the chance to get a look in,
issuing DoEvents throughout the code that updates the progress bar. Beyond
that, we would need to see the code.

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Alex St-Pierre" wrote in message
...
Hi !
When I click on form1 (execute button), I close form1 and open a form2
which
indicate a process bar and there is a Cancel button to stop the macro.
When I
click on it, the macro continue to run. Is there a way to stop the macro?
Thanks!!
Alex

'Userform1:
Private Sub CreateReport_Click()
UserForm1.Hide
UserForm2.Show
End
End Sub
'Userform2:
Private Sub UserForm_Activate()
Call MainMacro
Unload UserForm2
End Sub
Private Sub CommandButtonCancel_Click()
End 'doesn't work
End Sub
--
Alex St-Pierre




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default How to stop macro with cancel button

Hi!
I tried to add "DoEvents" in the sub that update the process bar but I have
to press continue at each 2 seconds. I don't press on anything. Any idea?
Here is example of lines where the macro stop:
UserForm1.Show
rng.Select
jBegin = jBegin + 1
iColTot = Selection.Columns.Count
wsTmp.Activate
End if
--
Alex St-Pierre


"Bob Phillips" wrote:

Your code needs to give the form button press the chance to get a look in,
issuing DoEvents throughout the code that updates the progress bar. Beyond
that, we would need to see the code.

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Alex St-Pierre" wrote in message
...
Hi !
When I click on form1 (execute button), I close form1 and open a form2
which
indicate a process bar and there is a Cancel button to stop the macro.
When I
click on it, the macro continue to run. Is there a way to stop the macro?
Thanks!!
Alex

'Userform1:
Private Sub CreateReport_Click()
UserForm1.Hide
UserForm2.Show
End
End Sub
'Userform2:
Private Sub UserForm_Activate()
Call MainMacro
Unload UserForm2
End Sub
Private Sub CommandButtonCancel_Click()
End 'doesn't work
End Sub
--
Alex St-Pierre






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default How to stop macro with cancel button

It's not the doevents.. I don't know why but even if I remove the line, my
program break every 2 seconds.. it's very strange at any line. If I do a F8
or continue, it runs until the next stop.

--
Alex St-Pierre


"Bob Phillips" wrote:

Your code needs to give the form button press the chance to get a look in,
issuing DoEvents throughout the code that updates the progress bar. Beyond
that, we would need to see the code.

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Alex St-Pierre" wrote in message
...
Hi !
When I click on form1 (execute button), I close form1 and open a form2
which
indicate a process bar and there is a Cancel button to stop the macro.
When I
click on it, the macro continue to run. Is there a way to stop the macro?
Thanks!!
Alex

'Userform1:
Private Sub CreateReport_Click()
UserForm1.Hide
UserForm2.Show
End
End Sub
'Userform2:
Private Sub UserForm_Activate()
Call MainMacro
Unload UserForm2
End Sub
Private Sub CommandButtonCancel_Click()
End 'doesn't work
End Sub
--
Alex St-Pierre




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default How to stop macro with cancel button

Where is the code managing the progress bar?

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Alex St-Pierre" wrote in message
...
Hi!
I tried to add "DoEvents" in the sub that update the process bar but I
have
to press continue at each 2 seconds. I don't press on anything. Any idea?
Here is example of lines where the macro stop:
UserForm1.Show
rng.Select
jBegin = jBegin + 1
iColTot = Selection.Columns.Count
wsTmp.Activate
End if
--
Alex St-Pierre


"Bob Phillips" wrote:

Your code needs to give the form button press the chance to get a look
in,
issuing DoEvents throughout the code that updates the progress bar.
Beyond
that, we would need to see the code.

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"Alex St-Pierre" wrote in
message
...
Hi !
When I click on form1 (execute button), I close form1 and open a form2
which
indicate a process bar and there is a Cancel button to stop the macro.
When I
click on it, the macro continue to run. Is there a way to stop the
macro?
Thanks!!
Alex

'Userform1:
Private Sub CreateReport_Click()
UserForm1.Hide
UserForm2.Show
End
End Sub
'Userform2:
Private Sub UserForm_Activate()
Call MainMacro
Unload UserForm2
End Sub
Private Sub CommandButtonCancel_Click()
End 'doesn't work
End Sub
--
Alex St-Pierre






  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to stop macro with cancel button

If you post your code, then we won't have to guess at what your code is
doing or how you attempted to implement the suggestion about DoEvents.

Rick


"Alex St-Pierre" wrote in message
...
It's not the doevents.. I don't know why but even if I remove the line, my
program break every 2 seconds.. it's very strange at any line. If I do a
F8
or continue, it runs until the next stop.

--
Alex St-Pierre


"Bob Phillips" wrote:

Your code needs to give the form button press the chance to get a look
in,
issuing DoEvents throughout the code that updates the progress bar.
Beyond
that, we would need to see the code.

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"Alex St-Pierre" wrote in
message
...
Hi !
When I click on form1 (execute button), I close form1 and open a form2
which
indicate a process bar and there is a Cancel button to stop the macro.
When I
click on it, the macro continue to run. Is there a way to stop the
macro?
Thanks!!
Alex

'Userform1:
Private Sub CreateReport_Click()
UserForm1.Hide
UserForm2.Show
End
End Sub
'Userform2:
Private Sub UserForm_Activate()
Call MainMacro
Unload UserForm2
End Sub
Private Sub CommandButtonCancel_Click()
End 'doesn't work
End Sub
--
Alex St-Pierre





  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default How to stop macro with cancel button

Hi Bob,
Finally, I have reboot my computer and the program run without stoping
anywhere..
The DoEvents works. Every time I update the processbar, I execute DoEvents.
Thanks!
Alex

Sub ProcessBar(ProcessPerc As Variant, ProcessLabel As String)
'ProcessPerc go from 0 to 1
DoEvents
With UserForm3
.Caption = Format(ProcessPerc, "0%")
.LabelPROGBAR.Width = UserForm3.Width * Avancement
.TextBoxPROGBAR.Text = ProcessLabel
.Repaint
End With
End Sub
--
Alex St-Pierre


"Bob Phillips" wrote:

Where is the code managing the progress bar?

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Alex St-Pierre" wrote in message
...
Hi!
I tried to add "DoEvents" in the sub that update the process bar but I
have
to press continue at each 2 seconds. I don't press on anything. Any idea?
Here is example of lines where the macro stop:
UserForm1.Show
rng.Select
jBegin = jBegin + 1
iColTot = Selection.Columns.Count
wsTmp.Activate
End if
--
Alex St-Pierre


"Bob Phillips" wrote:

Your code needs to give the form button press the chance to get a look
in,
issuing DoEvents throughout the code that updates the progress bar.
Beyond
that, we would need to see the code.

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"Alex St-Pierre" wrote in
message
...
Hi !
When I click on form1 (execute button), I close form1 and open a form2
which
indicate a process bar and there is a Cancel button to stop the macro.
When I
click on it, the macro continue to run. Is there a way to stop the
macro?
Thanks!!
Alex

'Userform1:
Private Sub CreateReport_Click()
UserForm1.Hide
UserForm2.Show
End
End Sub
'Userform2:
Private Sub UserForm_Activate()
Call MainMacro
Unload UserForm2
End Sub
Private Sub CommandButtonCancel_Click()
End 'doesn't work
End Sub
--
Alex St-Pierre






Reply
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
How to get userform Cancel button to invoke Exit Sub in calling macro? Craig Remillard New Users to Excel 1 November 19th 09 03:55 AM
Cancel button to cancel the whole macro excelnut1954 Excel Programming 3 January 17th 06 08:27 PM
Cancel Macro is user selects 'cancel' at save menu Mark Excel Programming 1 April 6th 05 05:45 PM
how to stop program with loop by click "Cancel" button miao jie Excel Programming 2 December 16th 04 02:42 PM
Button To Cancel Macro Bill Lunney Excel Programming 0 July 16th 03 10:27 PM


All times are GMT +1. The time now is 12:11 PM.

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

About Us

"It's about Microsoft Excel"