diff --git a/Event_ProgressBar.bas b/Event_ProgressBar.bas deleted file mode 100644 index 4ce8782..0000000 --- a/Event_ProgressBar.bas +++ /dev/null @@ -1,27 +0,0 @@ -Attribute VB_Name = "Event_ProgressBar" -Option Explicit -Option Base 1 - -Sub ShowStatus() - ProgressForm.Show -End Sub - -Sub TimeFrame(pauseTime As Double) - Start = Timer - Do - DoEvents - Loop Until (Timer - Start) >= pauseTime -End Sub - -Sub SampleEventStatusGenerator() - Dim i As Long - For i = 0 To 100 - Call UpdateProgressBar(i) - Call TimeFrame(0.1) - Next i -End Sub - -Sub UpdateProgressBar(lngPercentComplete As Long) - ProgressForm.Bar.Width = 2 * lngPercentComplete - ProgressForm.Status.Caption = lngPercentComplete & "% Complete" -End Sub diff --git a/Form Setup ReadMe.txt b/Form Setup ReadMe.txt deleted file mode 100644 index d94c2a8..0000000 --- a/Form Setup ReadMe.txt +++ /dev/null @@ -1,53 +0,0 @@ -Form Setup: - 1. Form: Change caption to progress indicator - 2. Frame: Add frame control - a. Clear caption - b. Height = 24 - c. Width = 204 - 3. Label: Add outside frame - a. Change caption to 0% Completed - 4. Label: Add inside frame - a. Change BackColor to Highlight - b. Clear caption - c. Height=20 - d. Width=10 (min of 0, max of 200) - e. Top and Left offset = 0 - -Form: -Private Sub UserForm_Activate() - Call SampleEventStatusGenerator - Unload ProgressForm -End Sub - -Private Sub UserForm_Initialize() - ProgressForm.Status.Caption = "0% Complete" - ProgressForm.Bar.Width = 10 -End Sub - -Module: -Option Explicit -Option Base 1 - -Sub ShowStatus() - ProgressForm.Show -End Sub - -Sub TimeFrame(pauseTime As Double) - Start = Timer - Do - DoEvents - Loop Until (Timer - Start) >= pauseTime -End Sub - -Sub SampleEventStatusGenerator() - Dim i As Long - For i = 0 To 100 - Call UpdateProgressBar(i) - Call TimeFrame(0.1) - Next i -End Sub - -Sub UpdateProgressBar(lngPercentComplete As Long) - ProgressForm.Bar.Width = 2 * lngPercentComplete - ProgressForm.Status.Caption = lngPercentComplete & "% Complete" -End Sub diff --git a/Progress Bar.xlsm b/Progress Bar.xlsm deleted file mode 100644 index 9857922..0000000 Binary files a/Progress Bar.xlsm and /dev/null differ diff --git a/ProgressExamples.bas b/ProgressExamples.bas new file mode 100644 index 0000000..e56a1c0 --- /dev/null +++ b/ProgressExamples.bas @@ -0,0 +1,135 @@ +Attribute VB_Name = "ProgressExamples" +Public Sub example() +' example() +' no parameters +' Provides a time based example for the ProgressForm + + Dim i As Long + + ' Displays the ProgressForm and initializes it + ProgressForm.start + + 'simply a loop to do something for showing the ProgressForm + For i = 0 To 100 Step 6 + ' Updates the % on the ProgressForm + ProgressForm.update i + + Application.Wait (Now + TimeValue("0:00:01")) + Next + + ' hides the ProfessForm and cleans up + ProgressForm.done +End Sub + + +Public Sub example2() +' example2() +' no parameters +' Provides a time based example for the ProgressForm with a different Caption + + Dim i As Long + + ' Displays the ProgressForm and initializes it + ProgressForm.start ("Are we done yet?") + + For i = 0 To 100 Step 6 + ProgressForm.update i + Application.Wait (Now + TimeValue("0:00:01")) + Next + ProgressForm.done +End Sub + + +Public Sub example3() +' example3() +' no parameters +' Provides a time based example for the ProgressForm with macro interruption + + Dim i As Long + + ' Displays the ProgressForm and initializes it + Call ProgressForm.start(, True) + + ' or any of the following + 'ProgressForm.start , True + 'ProgressForm.start "With Interrupt", True + 'ProgressForm.start bInterrupt:=True + + + For i = 0 To 100 Step 6 + ProgressForm.update i + Application.Wait (Now + TimeValue("0:00:01")) + Next + ProgressForm.done +End Sub + + +Public Sub example4() +' example4() +' no parameters +' Provides a time based example using a label with the progress + + Dim i As Long + ProgressForm.start + + For i = 0 To 5 + ' Updates the % on the ProgressForm with a label + ProgressForm.update (i / 5 * 100), "Performing Task: " & i + + Application.Wait (Now + TimeValue("0:00:01")) + Next + + ' hides the ProfessForm and cleans up + ProgressForm.done +End Sub + + + +'finally an example that does something useful +Public Sub clearBlankCells() +' clearBlankCells +' parameters: none are provided, but uses Selection to specify the range of cells to clear +' if selection is a single cell, the entire active range is used +' Removes blank cells (cells that are empty) and blank rows (rows that have no non-empty cells) +' + Dim r As Range ' area to manipulate + Dim i As Long, j As Long ' indicies + Dim x As Long, y As Long ' dimensions + Dim isBlank As Boolean ' blank row text + + + Set r = Selection + If (r.rows.Count = 1 And r.columns.Count = 1) Then + Set r = Range(Range("A1"), Range("A1").SpecialCells(xlCellTypeLastCell)) + End If + + x = r.rows.Count + y = r.columns.Count + + Set r = r(1) + +' Displays the ProgressForm and initializes it +ProgressForm.start + + For i = x - 1 To 0 Step -1 + isBlank = True + For j = y - 1 To 0 Step -1 + If (IsEmpty(r.Offset(i, j))) Then + r.Offset(i, j).Delete (xlToLeft) + Else + isBlank = False + End If + Next + If isBlank Then + r.Offset(i, y).EntireRow.Delete + End If + +' Updates the % on the ProfressForm +ProgressForm.update CLng((x - i) / x * 100) + + Next + +' hides the ProfessForm and cleans up +ProgressForm.done + +End Sub diff --git a/ProgressForm.frm b/ProgressForm.frm index 9b769d9..21a7922 100644 --- a/ProgressForm.frm +++ b/ProgressForm.frm @@ -1,7 +1,7 @@ VERSION 5.00 Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} ProgressForm - Caption = "Progress Indicator" - ClientHeight = 1080 + Caption = "Progress" + ClientHeight = 1995 ClientLeft = 120 ClientTop = 465 ClientWidth = 4395 @@ -13,14 +13,35 @@ Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False -Private Sub UserForm_Activate() - Call SampleEventStatusGenerator - Unload ProgressForm +Option Explicit + +Private Sub InterruptButton_Click() + Application.SendKeys "^{BREAK}" End Sub +Private Sub UserForm_Initialize() + ProgressForm.Status.Caption = "0% Complete" + ProgressForm.Bar.Width = 10 +End Sub -Private Sub UserForm_Initialize() - ProgressForm.Status.Caption = "0% Complete" - ProgressForm.Bar.Width = 10 +Sub start(Optional strCaption As String = "Progress", Optional bInterrupt As Boolean = False) + InterruptButton.Visible = bInterrupt + ProgressForm.Caption = strCaption + ProgressForm.Show (0) +End Sub + + +Sub update(lngPercentComplete As Long, Optional strStatus As String = "") + + ProgressForm.Bar.Width = 2 * lngPercentComplete + ProgressForm.Status.Caption = lngPercentComplete & "% Complete" + + SubStatus.Caption = strStatus + DoEvents End Sub + +Sub done() + Unload ProgressForm +End Sub + diff --git a/ProgressForm.frx b/ProgressForm.frx index 098d977..d5fe252 100644 Binary files a/ProgressForm.frx and b/ProgressForm.frx differ diff --git a/README.md b/README.md index bc0a095..2c09450 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,22 @@ # ExcelVBA_ProgressBar -Launches a customizable userform that displays as an animated progress bar dependent upon a percent complete status. +Creates a simple non-modal dialog in Excel +Used to effectively show the progress of a macro + +## Installation +1) Download +2) In Excel VBA Editor: + + File -> Import File ... + + Select ProgressForm.frm + + Optionally, repeat for ProgressExamples.bas + +## Usage +``` +Sub example() + ProgressForm.start # displays the ProgressForm + ProgressForm.update pct # updates the ProgressForm to pct% + ProgressForm.done # hides the ProgressForm +End Sub +``` + +## License +GNU Public License