English | Русский | UserForms-Class-ALL
A comprehensive VBA class for displaying a customizable progress bar during long-running operations in Excel or other Office applications.
The clsProgresBar class provides an easy-to-use interface for displaying progress during long-running operations. It features a clean, customizable interface with support for dual messages, visual indicators, and user cancellation.
- Dual Message Display: Top and bottom message areas for detailed progress information
- Visual Progress Indicator: Animated progress line with customizable colors
- User Cancellation: Support for cancelling operations with the Esc key
- Customizable Appearance: Configurable symbols, colors, and dimensions
- Performance Optimized: Efficient updates to minimize UI lag
- Error Handling: Comprehensive error management and reporting
- Time Tracking: Built-in timer to track operation duration
- Logging Capability: Automatic logging of progress events
- Import the class module
clsProgresBar.clsinto your VBA project - Import the form module
frmProgresBar_2.frminto your VBA project - Use the class in your code as shown in the usage examples
Sub ExampleUsage()
Dim oProg As clsProgresBar
Set oProg = New clsProgresBar
' Initialize the progress bar
oProg.Initialize "Processing data...", "Data Processing", "Initializing...", _
enumTypeCaptionLabel.enProcent, 100
' Simulate a long-running operation
Dim i As Long
For i = 1 To 100
' Update progress bar
oProg.Update i / 10, "Processing item " & i
Next i
Set oProg = Nothing
End SubSub AdvancedExample()
Dim oProg As clsProgresBar
Set oProg = New clsProgresBar
' Initialize with custom settings
oProg.Initialize "Loading files...", "File Loader", "Starting up...", _
enumTypeCaptionLabel.enAll, 500, RGB(0, 128, 255), RGB(20, 200, 200), "|", True, "*"
' Resize the progress bar
oProg.Resize 600, 40, 30, 20
' Process with progress updates
Dim i As Long
For i = 1 To 500
If oProg.Update(i / 500, "File " & i & " of 500", 500) Then
' User requested cancellation (Update returned True)
Exit For
End If
' When Update returns False, continue with the operation
' Add delay to simulate work
Application.Wait Now + TimeValue("0:00:01")
Next i
' Access log data if needed
Dim logData As Variant
logData = oProg.LogData
Set oProg = Nothing
End SubDefines the type of information displayed on the progress bar:
enNone: No information displayedenProcent: Percentage onlyenValue: Current/Total valuesenTime: Elapsed timeenProcentValue: Percentage and valueenProcentTime: Percentage and elapsed timeenValuTime: Value and elapsed timeenAll: All information types
Provides access to version information:
enName: Class nameenAuthor: Author nameenVersion: Version stringenLicense: License informationenDateOfCreation: Creation dateenDateOfUpdate: Last update dateenDescription: Description textenAll: All version information
Initialize(sHeaderCaption As String, sMessageTop As String, sMessageBottom As String, TypeCaptionLabel As enumTypeCaptionLabel, Optional LineFrontColor As XlRgbColor = -1, Optional LineBackColor As XlRgbColor = -1, Optional sLineFrontSimvol As String = "|", Optional bPictureShow As Boolean = False, Optional sPictureSimvol As String = vbNullString)
Initializes the progress bar with specified parameters.
sHeaderCaption: Text for the form captionsMessageTop: Message to display in the top message areasMessageBottom: Message to display in the bottom message areaTypeCaptionLabel: Type of information to displayLineFrontColor: Color of the front progress line (optional)LineBackColor: Color of the back progress line (optional)sLineFrontSimvol: Character to use for the progress line (optional)bPictureShow: Whether to show the progress indicator symbol (optional)sPictureSimvol: Symbol to display at the progress position (optional)
Update(procent As Single, sMessageBottom As String, CountItems As Long, Optional LineFrontColor As XlRgbColor = -1, Optional LineBackColor As XlRgbColor = -1) As Boolean
Updates the progress bar with new values and returns True if user requested cancellation, False otherwise.
procent: Progress percentage (0.0 to 1.0)sMessageBottom: Message to display in the bottom message areaCountItems: Total number of items (required)LineFrontColor: New color for front progress line (optional)LineBackColor: New color for back progress line (optional)
Resize(WidthForm As Single, HeightMessageTop As Single, HeightMessageBottom As Single, HeightLineProgres As Single)
Changes the size of the progress bar.
WidthForm: Form widthHeightMessageTop: Top message heightHeightMessageBottom: Bottom message heightHeightLineProgres: Progress line height
Gets or sets the form header text.
Gets or sets the top message text.
Gets or sets the bottom message text.
Gets or sets the visibility of the progress indicator symbol.
Gets or sets the progress indicator symbol text.
Gets or sets the color of the progress indicator symbol.
Gets or sets the color of the progress line.
Gets or sets the color of the progress line background.
Gets the elapsed time since initialization.
Gets or sets the type of caption label.
Gets the log data array containing progress events.
The class handles potential errors gracefully:
- Invalid percentage values are normalized to the 0-1 range
- Division by zero is prevented in calculations
- Proper cleanup occurs in the Class_Terminate event
The progress bar can be customized in several ways:
- Colors for progress line and indicator symbol
- Size and dimensions
- Visibility of the indicator symbol
- Header and message text
- Progress indicator symbol
- Type of information displayed (percentage, values, time, etc.)
The implementation is optimized for performance by:
- Efficient UI updates
- Proper memory management
- Minimizing expensive operations during updates
- Using DoEvents to maintain UI responsiveness
Apache License 2.0
