-
Hi,
I'm new here and desperately in need of help.
I am struggling with code to create a userform which has a Cancel button. I want this rather long task to be performed as long as the user does not click the Cancel button. Otherwise it should keep performing the tasks until the whole document has been covered.
I think the way to go about his is to create a Timer control on my form, which will keep performing the task, unless cancelled by the user.
The problem is that the Timer Control is not available in Microsoft Word 97 Visual Basic for Applications. How can I port Visual Basic's Timer Control into Microsoft Word 97. Please help.
Thanks in advance.
Shr
-
The Keyword here is DoEvents, DoEvents tells VB to go and check if it's got any new messages, ie if the mouse has been clicked, esc has been pressed, etc. Make sure thre's a DoEvents in any big loops. That should sort it.
Code:
For i = 1 To 10000
Debug.Print i
Next i
won't let the user hit cancel
Code:
For i = 1 To 10000
Debug.Print i
DoEvents
Next i
will
Hope this helps
-
you could alos use application.ontime :)
-
If youre performing an operation within a loop and want to cancel it by pressing a button:
The loop:
Code:
Do
.
.
DoEvents
Loop Until cancelled
The command button:
Code:
Private Sub Command1_Click()
cancelled = True
End Sub
Also a for next loop can be cancelled by exit for.