98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Integrate Excel VBA Progress Bar into Existing Macro
Integrate Excel VBA Progress Bar into Existing Macro
Resolved · Medium Priority · Version 2010
Martin has attended:
Excel VBA Introduction course
Excel Advanced course
Integrate Excel VBA Progress Bar into Existing Macro
I'm trying to integrate a VBA Progress Bar into an existing macro, which takes about 5 minutes to run, so that the end-user knows that the macro is progressing. I have a userform with a progress bar designed, but I'm stuck as to how to make it run, showing % complete while the macro is running.
In short, I have a workbook of 300+ clients, each with their own named worksheet. The macro builds an index of all their names, based on the worksheet name, as follows:
Sub ListClientDataSheets()
Sheets("Client Index").Select
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
Application.DisplayAlerts = False
'Unprotects the Client Index worksheet
ActiveSheet.Unprotect ("xxxxxxxx")
If MsgBox("Please wait while the Client Index is compiled..." _
& vbCrLf & vbCrLf & "This may take up to 5 minutes, depending on" _
& vbCrLf & "the number of Clients stored in the database" _
& vbCrLf & vbCrLf & "Click OK to continue or Cancel to abort", _
vbOKCancel + vbInformation, "Compiling the Client Index") = vbCancel Then Exit Sub
'Unhides the first 9 non-client (performance) sheets and clears the existing index
Rows("1:9").Select
Range("A9").Activate
Selection.EntireRow.Hidden = False
Range("B1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
Range("B1").Select
ActiveWindow.SmallScroll Down:=9
Application.ScreenUpdating = True
Application.ScreenUpdating = False
'Sorts the existing Client sheets alphabetically by calling the SortDataSheets macro
SortDataSheets
Sheets("Client Index").Select
Application.Calculation = xlCalculationAutomatic
'Compiles the list of all the worksheet names
Dim Index As Worksheet
Set Index = Application.ActiveSheet
For i = 1 To Application.Sheets.Count
Index.Range("B" & i) = Application.Sheets(i).Name
Next i
'Hides the first 9 worksheet names (performance), leaving only the Client names visible
Rows("1:9").Select
Selection.EntireRow.Hidden = True
Range("B10").Select
Application.ScreenUpdating = True
'Re-protects the Client Index worksheet
ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=False, AllowSorting:=True, Password:="xxxxxxxx"
MsgBox "Thank you for your patience... the Index is now complete!", vbInformation
Application.EnableEvents = True
Application.DisplayAlerts = True
End Sub
RE: Integrate Excel VBA Progress Bar into Existing Macro
Hello Martin,
Thank you for your question. Running events such as progress bars are covered in our VBA Advanced course which I don't deliver, but I might have a suggestion or two on how to add the code to a Userform. If my advice doesn't help, please post again and then one of my colleagues who runs the advanced course will be able to help you.
My guess is that you want the progress bar to start along with the other macro when you click the OK button of the userform. To do this, in the workbook, you need to open the Visual Basic Editor by pressing F11. In the Project Explorer on the left, there should be a folder called Forms. Open this to show the userform inside. When you double click on the userform, it opens in design view. Double click the OK button to reveal the macros which will run when you run the userform.
This is where you can paste a copy of the other macro's code to make it start with the Progress Bar. I would suggest placing the Progress Bar code before the other macro's code, to ensure it starts showing the progress immediately.
As I mentioned before, this is my best guess. If this makes sense, give it a try, otherwise please post again to get some more assistance.
Kind regards
Marius Barnard
Excel Trainer
RE: Integrate Excel VBA Progress Bar into Existing Macro
Hi Martin,
For clarity, this is the thread we will be using for continuity. The others have now been marked off.
Our senior trainer will respond as soon as he is next available.
Kind regards,
Richard
RE: Integrate Excel VBA Progress Bar into Existing Macro
Hi Martin!
I have been looking at some option for showing the progress when running a macro.
I have attached a workbook with one solution where you are using the Excel progress bar in the down left corner. The example shows the real progress.
You have another more complicated solution where you are creating a vba userform and in the userform you are coding several coloured lables to to appear on top of each other to indicate a progress.
I hope that I have pointed you in the right direction.
Kind regards
Jens Bonde
Microsoft Office Specialist Trainer
Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us
London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector
Attached files...
RE: Integrate Excel VBA Progress Bar into Existing Macro
Thanks Jans, the userform is the solution I'm aiming at - I'm probably being a little dim, but where do I find the attachment?
RE: Integrate Excel VBA Progress Bar into Existing Macro
Hi Martin,
A very good explanation and all the code you need you can find here:
https://support.microsoft.com/en-us/kb/211736
Most examples is faked progress indicators which doesn't give a real indication of the progress.
Please have a look at the example and let me know if you cannot get it to work.
Kind regards
Jens Bonde
Microsoft Office Specialist Trainer
Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us
London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector
RE: Integrate Excel VBA Progress Bar into Existing Macro
Thanks Jens, I've tried similar examples, but can't figure out how to get it to run in tandem with the macro I included, which is processing worksheet names rather than rows. In effect, does my ListClientDataSheets become 'Main' in the example, into which I place code which loops through the worksheets rather than rows? In which case, where does the code go? It's all a bit of a mystery!
RE: Integrate Excel VBA Progress Bar into Existing Macro
Hi Martin,
Unfortunately I have not been able to find a way of doing it. The problem is that the userform do not allow you to do something in another sheet. When its open it will lock Excel from going to another sheet.
I cannot help you with this one but still you can use the first example using Excel's own progress bar.
Kind regards
Jens Bonde
Microsoft Office Specialist Trainer
Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us
London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector
Training information:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Adding up time greater than 24 hoursWhen you add up time if it exceeds 24 hours i.e 27 hours appears as 03:00. Go to Format / Cells / Number / Custom. The format is hh:mm but if change it to [hh]:mm it will add up to the correct amount of hours. |