Where are you placing the code? You need to declare the object
WithEvents in a class module (e.g., a regular class module, a
sheet module, a userform, or the ThisWorkbook module). It won't
work if you declare the object in a regular module, since regular
code modules can't trap events.
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
"FrigidDigit" wrote in message
...
Bob,
Just a question. Once my procedure starts running, the dialog
box does not have focus and trying to click on the cancel
button has no effect.
What am I doing wrong? Please let me know which code snippets
you need to see to help.
Thank you very much!
FD
"Bob Phillips" wrote in
message ...
FD,
As far as I can see, you don't need to do anything. The DLL
handles cancels
quite nicely itself, all you need to do is to click the
button.
If you mean that you want to interrupt the Cancel event and do
some of your
own processing, then you need to create a class to catch the
events. The
class code would look something like this
Option Explicit
Public WithEvents PB As ProgressReporter.Progressor
Public Sub PB_UserCancel(Cancel As Boolean)
MsgBox "Interrupted"
End Sub
and using Chip's example you would invoke it like this,
assuming the class
module is named clsEventSink,
Option Explicit
Dim Prog As ProgressReporter.Progressor
Dim cPB As clsEventSink
Sub Test()
Dim N As Long
Set Prog = New ProgressReporter.Progressor
Set cPB = New clsEventSink
Set cPB.PB = Prog
With Prog
.MinimumValue = 0
.MaximumValue = 10000
.SetParentWindow 0
.CurrentValue = 0
.Show
For N = 1 To 10000
'
' your code here
'
DoEvents
.Increment 1
Next N
End With
Set cPB = Nothing
Set Prog = Nothing
End Sub
--
HTH
RP
(remove nothere from the email address if mailing direct)
"FrigidDigit" wrote in
message
...
Hi Chip,
I am using your progress reporter dll and it works very
nicely.
Unfortunately, I am too stupid to write the code to enable
the user to
cancel the loop by clicking on the dialog's cancel button.
Can you give me
some guidance please?
FD