-
Progress Bar
I want to insert a progress bar in my Word VBA program macro at a specific (RowNumber, ColumnNumbar and ParaNumber) location. The value of the progress bar will be 25% or 50% or 75% or 100%. The label for the progress bar will be inserted within a frame. Both the label and the frame need to have a some background color.
I will appreciate if someone can help me to get started with a sample code that I can work around to move ahead. Thanks
-
-
Hi Chas, Thanks for your reply. All the links, sent by you, point to examples that show the progress on a USERFORM when the macro is running. I do not want to create a UserForm since I want the progress bar to appear at a specific location in my word Table (RowNumber, ColumnNumber, ParaNUmber). The value of the progress bar is fixed at 25%/ 50%/ 75%/ 100%. It will be static as opposed to the dynamic progress shown on the threads forwarded by you. It will be helpful if there is a sample code.
-
-
Fellow contributors are right about progress bars, but you may be able to simulate a progress bar in your table by embedding a four cell table in one of the cells, then call the following macro to colour the cells according to a value that you wish to log. In the example code, the cells are coloured according to the value in the calling macro - here 50
Code:
Option Explicit
Sub Macro1()
'call the bar
ProgressBar 50
End Sub
Sub ProgressBar(lngVal As Long)
'Graham Mayor - https://www.gmayor.com - Last updated - 30 Nov 2022
Dim oTable As Table
Dim oNestedTable As Table
Dim oCell1 As Cell, oCell2 As Cell, oCell3 As Cell, oCell4 As Cell
Set oTable = ActiveDocument.Tables(1)
For Each oNestedTable In oTable.Tables
Set oCell1 = oNestedTable.Range.Cells(1)
Set oCell2 = oNestedTable.Range.Cells(2)
Set oCell3 = oNestedTable.Range.Cells(3)
Set oCell4 = oNestedTable.Range.Cells(4)
Select Case True
Case Is = lngVal = 100
MsgBox "100"
oCell4.Shading.BackgroundPatternColor = wdColorGreen
oCell3.Shading.BackgroundPatternColor = wdColorGreen
oCell2.Shading.BackgroundPatternColor = wdColorGreen
oCell1.Shading.BackgroundPatternColor = wdColorGreen
Case Is = lngVal >= 75 And lngVal < 100
oCell4.Shading.BackgroundPatternColor = wdColorWhite
oCell3.Shading.BackgroundPatternColor = wdColorGreen
oCell2.Shading.BackgroundPatternColor = wdColorGreen
oCell1.Shading.BackgroundPatternColor = wdColorGreen
Case Is = lngVal >= 50 And lngVal < 75
oCell4.Shading.BackgroundPatternColor = wdColorWhite
oCell3.Shading.BackgroundPatternColor = wdColorWhite
oCell2.Shading.BackgroundPatternColor = wdColorGreen
oCell1.Shading.BackgroundPatternColor = wdColorGreen
Case Is = lngVal >= 25 And lngVal < 50
oCell4.Shading.BackgroundPatternColor = wdColorWhite
oCell3.Shading.BackgroundPatternColor = wdColorWhite
oCell2.Shading.BackgroundPatternColor = wdColorWhite
oCell1.Shading.BackgroundPatternColor = wdColorGreen
Case Is = lngVal >= 0 And lngVal < 25
oCell4.Shading.BackgroundPatternColor = wdColorWhite
oCell3.Shading.BackgroundPatternColor = wdColorWhite
oCell2.Shading.BackgroundPatternColor = wdColorWhite
oCell1.Shading.BackgroundPatternColor = wdColorWhite
End Select
Next oNestedTable
lbl_Exit:
Set oTable = Nothing
Set oNestedTable = Nothing
Set oCell1 = Nothing
Set oCell2 = Nothing
Set oCell3 = Nothing
Set oCell4 = Nothing
Exit Sub
End Sub
-
Thank you very much for your suggestion. I could work around to get my solution