High Plains Grifter
Board Regular
- Joined
- Mar 9, 2010
- Messages
- 129
Hello People,
I have a macro which takes a looong time to execute - opening 20+ files and copying information from each into one master file. I have used the
command to stop the screen jumping all over the place while this happens, which is a greaet improvement, but I have recently had a couple of users breaking the whole thing by thinking their computer had frozen up while the macro was running.
Is there any way in which a Msgbox might be made to appear which would show the number of files that have been sampled out of the total to sample? Even better, if this could display a status bar based on the percentage of the task completed?
Given that the core of the profgram is a For...To loop, counting up to the total number of workbooks to sample, the counter would not be a problem, but how do I make it remain in place without requiring input from users? How do I make it disappear when the program completes, and yet remain if other message boxes appear during the program?
I was thinking something along the lines of this for the box (this is extracted from the macro, missing out most of the code)
The formula in H1 is Rept("|",I1). This works in a way... But the msg box causes the program to pause, and waits for a response from the user - I would like it to stay visible while the program runs in the background, and update the bar progress by an increment of i/t each time the For..Next loop restarts. Also, the bar is rudimentary to say the least - I could work on that if I knew how to make the Msgbox behave.
The box could disappear or change to Finished! when the macro completes. Is this possible? If someone were to show a way to make the Msgbox stay visible and not interfere with the program, I could probably work out the rest myself.
Any help gratefully received, and thanks for reading!
I have a macro which takes a looong time to execute - opening 20+ files and copying information from each into one master file. I have used the
Code:
application.screenupdates = false
Is there any way in which a Msgbox might be made to appear which would show the number of files that have been sampled out of the total to sample? Even better, if this could display a status bar based on the percentage of the task completed?
Given that the core of the profgram is a For...To loop, counting up to the total number of workbooks to sample, the counter would not be a problem, but how do I make it remain in place without requiring input from users? How do I make it disappear when the program completes, and yet remain if other message boxes appear during the program?
I was thinking something along the lines of this for the box (this is extracted from the macro, missing out most of the code)
Code:
Dim Prog As Long
Dim Progress As String
For i = 0 To (t - 1)
Prog = i / t * 10
Sheets("Collate data").Activate
Range("I1").Value = Prog
Progress = Range("H1").Value
'all the gubbins of the actual macro - too long to include
Msg = ("Progress:" & Progress)
Ans = MsgBox(Msg)
Next i
The formula in H1 is Rept("|",I1). This works in a way... But the msg box causes the program to pause, and waits for a response from the user - I would like it to stay visible while the program runs in the background, and update the bar progress by an increment of i/t each time the For..Next loop restarts. Also, the bar is rudimentary to say the least - I could work on that if I knew how to make the Msgbox behave.
The box could disappear or change to Finished! when the macro completes. Is this possible? If someone were to show a way to make the Msgbox stay visible and not interfere with the program, I could probably work out the rest myself.
Any help gratefully received, and thanks for reading!