agarwaldvk
04-08-2013, 04:51 AM
Hi Everybody
I have an application whereby I have a progress bar that is supposed to show the time elapsed for the current process. I have, with help from some of the code that I found on the internet, got some code that actually does that. However, I am not able to show the progress bar update EXACTLY at one (1) second interval.
The code is shown below :-
Sub Main()
Dim PctDone As Single
Application.ScreenUpdating = False
Dim a As Date, b As Date, aOrig As Date
aOrig = Now()
a = Now() + 1 / 24 / 60 / 60
b = Now() + 1 / 24 / 60 / 60 * 30
While Now() <= b
'Application.Wait (500)
If Now() >= a Then
PctDone = (a - aOrig) * 24 * 3600 '/ 30
With UserForm1
.Caption = Format(PctDone, "0")
.LabelProgress.Width = PctDone * 180 / 30
End With
a = Now() + 1 / 24 / 60 / 60
End If
DoEvents
Wend
Unload UserForm1
End Sub
The user form correctly displays the progress bar but it is not updated at EXACTLY one (1) second - sometimes it is done at one (1) and at other times, it is updated at two (2) second intervals.
Can I get it to update at EXACTLY one (1) second interval?
This is being done is Excel VBA.
Best regards
Deepak
I have an application whereby I have a progress bar that is supposed to show the time elapsed for the current process. I have, with help from some of the code that I found on the internet, got some code that actually does that. However, I am not able to show the progress bar update EXACTLY at one (1) second interval.
The code is shown below :-
Sub Main()
Dim PctDone As Single
Application.ScreenUpdating = False
Dim a As Date, b As Date, aOrig As Date
aOrig = Now()
a = Now() + 1 / 24 / 60 / 60
b = Now() + 1 / 24 / 60 / 60 * 30
While Now() <= b
'Application.Wait (500)
If Now() >= a Then
PctDone = (a - aOrig) * 24 * 3600 '/ 30
With UserForm1
.Caption = Format(PctDone, "0")
.LabelProgress.Width = PctDone * 180 / 30
End With
a = Now() + 1 / 24 / 60 / 60
End If
DoEvents
Wend
Unload UserForm1
End Sub
The user form correctly displays the progress bar but it is not updated at EXACTLY one (1) second - sometimes it is done at one (1) and at other times, it is updated at two (2) second intervals.
Can I get it to update at EXACTLY one (1) second interval?
This is being done is Excel VBA.
Best regards
Deepak