Posted to microsoft.public.excel.programming
|
|
Progress Bar
Thanks for the help Bob, but I am new to VBA and don't even know what half of
the things you said are. Could you give me an example? That would help
alot. Thanks.
"Bob Phillips" wrote:
I've had a look at Robin's site and the whole demo.
What he does is to declare a Public variable of type Boolean in the module
that does the work, your code module. The form sets that variable to True if
the Cancel button is pressed.
You need to test that variable in your code, and when it becomes true, you
exit.
--
HTH
Bob Phillips
"John" wrote in message
...
Bob,
Here is the class Module code... any ideas thanks again for the help.
'PROGRESS BAR CLASS
'REQUIRES INCLUSION OF frmProgress Form
'COPYRIGHT of the AUTHOR: ROBIN HAMMOND
'UPDATED: 16 September 2003
'PURPOSE: Provides a modeless user form showing progress bar, title and
three
'captions in Excel 2000 or higher. Now handles Excel 97 by using same
methods
'with progress messages written to the statusbar
'LEGAL: You may use this code as is or with modifications in your programs
'No commercial use or sale of this code or derivative works is permitted
'under any circumstances without the express permission of the author.
'The author is likely to say yes if you ask nicely though.
'You may redistribute this workbook in its original form only, as
'first received from the Enhanced Datasystems website.
'For further information, please visit www.enhanceddatasystems.com
'The colour shading technique on the progress bar was done by
'Jamie Collins in response to a newsgroup challenge. Thanks Jamie.
Public DisableCancel As Boolean
Public Title As String
Private nVersion As Integer
Private strStatus As String
Private strStat1 As String
Private strStat2 As String
Private strStat3 As String
Private strProgress As String
Property Let Caption1(strCaption As String)
If nVersion < 9 Then
strStat1 = strCaption
UpdateStatus
Else
#If VBA6 Then
frmProgress.lblMsg1.Caption = strCaption
DoEvents
#End If
End If
End Property
Property Let Caption2(strCaption As String)
If nVersion < 9 Then
strStat2 = strCaption
UpdateStatus
Else
#If VBA6 Then
frmProgress.lblMsg2.Caption = strCaption
DoEvents
#End If
End If
End Property
Property Let Caption3(strCaption As String)
If nVersion < 9 Then
strStat3 = strCaption
UpdateStatus
Else
#If VBA6 Then
frmProgress.lblMsg3.Caption = strCaption
DoEvents
#End If
End If
End Property
Sub Finish()
If nVersion < 9 Then
Application.StatusBar = ""
Application.StatusBar = False
Else
#If VBA6 Then
Unload frmProgress
#End If
End If
End Sub
Sub Hide()
If nVersion < 9 Then
Application.StatusBar = ""
Application.StatusBar = False
Else
#If VBA6 Then
frmProgress.Hide
#End If
End If
End Sub
Property Let Progress(nWidth As Integer)
Dim nProgress As Integer
If nVersion < 9 Then
strProgress = CStr(nWidth)
UpdateStatus
Else
#If VBA6 Then
If nWidth 100 Then nWidth = 100
If nWidth < 0 Then nWidth = 0
With frmProgress.imgProgFore
.Width = 200 - Int(nWidth * 2)
.Left = 12 + Int(nWidth * 2)
End With
DoEvents
#End If
End If
End Property
Sub Reset()
If nVersion < 9 Then
Application.StatusBar = ""
Application.StatusBar = False
Else
#If VBA6 Then
Title = ""
frmProgress.lblMsg1.Caption = ""
frmProgress.lblMsg2.Caption = ""
frmProgress.lblMsg3.Caption = ""
DisableCancel = False
#End If
End If
End Sub
Sub Show()
If nVersion < 9 Then
'probably best to leave the title out of this
Else
#If VBA6 Then
With frmProgress
If DisableCancel = True Then
.Width = 228
.cmdCancel.Enabled = False
End If
.Caption = Title
.Show vbModeless
End With
#End If
End If
End Sub
Private Sub Class_Initialize()
nVersion = Val(Application.Version)
End Sub
Private Sub Class_Terminate()
If nVersion < 9 Then Application.StatusBar = False
End Sub
Private Sub UpdateStatus()
Dim strStatus As String
strStatus = strStat1
If strStat2 < "" Then strStatus = strStatus & ", " & strStat2
If strStat3 < "" Then strStatus = strStatus & ", " & strStat3
If strProgress < "" Then strStatus = strStatus & ", " & strProgress & "%"
Application.StatusBar = strStatus
End Sub
"Bob Phillips" wrote:
You need to look at the class module and see what it does when the
cancel
button is pressed. It will probably set a property, or could be changed
to
set a property. You will need to then read this property in your code
and
stop the execution.
--
HTH
Bob Phillips
"John" wrote in message
...
I was looking at a previous post to get a progress bar to work while
running
a lengthy macro. Below is the post on how to incorporate the progress
bar
into your code. That works fine expect for one thing. There is a
cancel
button on the progress bar, and when it is pushed the rest of my code
continues running. How do I end my code if I press cancel on the
progress
bar?
It would look something like this
Sub Main
Dim PB as clsProgBar
Set PB = new clsProgBar
'if your subs are being called from a userform, hide the form first
using
|