LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Monitoring progress of Excel/VBA routines with a long runtime


Here another simple statusbar progress routine:

Sub StatusProgressBar(lCounter As Long, _
lMax As Long, _
bReset As Boolean, _
Optional lInterval As Long = -1, _
Optional strLeadingText As String, _
Optional strTrailingText As String, _
Optional lLength As Long = 100)

'lCounter the loop counter passed from the procedure
'lMax the maximum of the loop counter
'bReset do this at the very first iteration, eg i = 0
'lInterval the update interval of the statusbar
'strText any text preceding the progressbar
'lLength lenght in characters of the progressbar
'---------------------------------------------------------
Dim lStripes As Long
Static lLenText As Long
Static strBuffer As String
Static lOldStripes As Long
Static lInterval2 As Long

If lMax = 0 Then
Exit Sub
End If

If bReset Then
lLenText = Len(strLeadingText)
strBuffer = strLeadingText
strBuffer = strBuffer & String(lLength, ".")
strBuffer = strBuffer & "|"
lOldStripes = 0

If lInterval = -1 Then
lInterval2 = (lMax / lLength) \ 2
Else
lInterval2 = lInterval
End If

If lInterval2 < 1 Then
lInterval2 = 1
End If
End If

If lCounter Mod lInterval2 = 0 Or lCounter = lMax Then
lStripes = Round((lCounter / lMax) * lLength, 0)

If lStripes lOldStripes Then

Mid$(strBuffer, lLenText + 1 + lOldStripes) = String(lStripes -
lOldStripes, "|")
strBuffer = strBuffer & strTrailingText

If Len(strBuffer) = 0 Then
Application.StatusBar = False
Else
Application.StatusBar = strBuffer
End If

lOldStripes = lStripes

End If 'If lStripes lOldStripes
End If 'If lCounter Mod lInterval2 = 0 Or lCounter = lMax

End Sub


The solution to your problem though is to use DoEvents.


RBS


"paparlz" wrote in message
...
I've recently been running heavy VBA computations in Excel that run
for many hours. It would be useful to know how the job is
progressing. I've tried putting a progress message in the status
bar; this works for while but always hangs up eventually, even
thought he job is progressing satisfactorily. I've tried writing
messages to a worksheet; this performs in a simialr way - eventually
the sheet fails to update. For the job I'm running at the moment I
cannot even make the workbook visible in windows; it is listed on the
windows taskbar, but cannot be restored to view. I know that progress
monitors for VBA are out there - I have used one in the past. But
does anyone know why Excel fails to update its own status bar or make
itself visible in these circumstances?


 
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
Interrupting long calculations in Excel? Hi all, I am having a verylong calculation in Excel using VBA. Of course I know I can hit ESC orCTRL+BREAK to interrupt the VBA program. But I found due to too long runningprocess, the Excel window stop to LunaMoon Excel Discussion (Misc queries) 3 July 31st 08 04:47 PM
Interrupting long calculations in Excel? Hi all, I am having a verylong calculation in Excel using VBA. Of course I know I can hit ESC orCTRL+BREAK to interrupt the VBA program. But I found due to too long runningprocess, the Excel window stop to LunaMoon Excel Programming 3 July 31st 08 04:47 PM
Does anyone have a Glucose Monitoring Template for Excel? mdehart64 Excel Discussion (Misc queries) 0 July 11th 07 03:14 AM
Gant Chart/Programme Progress Monitoring dd Excel Programming 2 May 15th 07 12:31 PM
Free Excel Templates for monitoring Student progress in a Youth E. Jacobsong Excel Discussion (Misc queries) 1 February 9th 05 11:49 AM


All times are GMT +1. The time now is 04:20 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"