Consulting

Results 1 to 6 of 6

Thread: Progress Bar

  1. #1
    VBAX Regular
    Joined
    Nov 2022
    Posts
    7
    Location

    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

  2. #2
    VBAX Contributor
    Joined
    Jul 2020
    Location
    Sun Prairie
    Posts
    119
    Location
    Start with an Internet search like https://duckduckgo.com/?q=vba+progre...=v248-1&ia=web.

  3. #3
    VBAX Regular
    Joined
    Nov 2022
    Posts
    7
    Location
    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.

  4. #4
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    For a true progress bar, you need a userform. The other option is to output the progress to the StatusBar. See, for example:
    Mail merge to individual files, there's any kind of progress indicator (msofficeforums.com)
    convert text numbers to real numbers, partial Cell deleting, deleting rows between se (vbaexpress.com)
    Retrieve the Font Type and Size Using VBA (vbaexpress.com)
    Exporting tracked changes and comments to excel (msofficeforums.com)
    Regardless, the output must be refreshed on each iteration, as it is volatile. In any event, your code needs to calculate what % has been reached on each iteration.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  5. #5
    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
    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
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  6. #6
    VBAX Regular
    Joined
    Nov 2022
    Posts
    7
    Location
    Thank you very much for your suggestion. I could work around to get my solution

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •