Application.AddProgressBar

This function adds a progress bar by the specified name to a queries collection.

Syntax Parameters Return Value
Function Application.AddProgressBar( _
    Name As String, _
    Optional MinCounter As Integer = 1, _
    Optional MaxCounter As Integer = 100, _
    Optional IncludeCancelButton As Boolean = True, _
    Optional Cycle As Boolean = False) As ProgressBar
  • Name [in]

The text to be displayed on the progress bar.

Type: String

  • MinCounter [in,optional]

The beginning range of the progress bar. This parameter defaults to 1.

Type: Integer

Default value: 1

  • MaxCounter [in,optional]

The ending range of the progress bar. This parameter defaults to 100.

Type: Integer

Default value: 100

  • IncludeCancelButton [in,optional ]

Whether or not to display a cancel button on the progress bar. This parameter defaults to True.

Type: Boolean

Default value: True

  • Cycle [in,optional]

Whether or not the progress bar should wrap around if it goes beyond its MaxCounter value while stepping.

Type: Boolean

Default value: False

ProgressBar

SVB Example

Displaying a progress bar:

Option Base 1
Option Explicit
Sub Main
    Dim n As Long,i As Long
    n = 1000
    'Create and dimension the spreadsheet object
    Dim s As New Spreadsheet
    'Set the size of the object
    s.SetSize(n,2)
    'Set up a progress bar
    Dim pb As ProgressBar
    Set pb = Application.AddProgressBar("Generating random numbers", 1, n)
    'Assign the random values
    For i = 1 To n
    If pb.Cancelled = True Then
        MsgBox "Random number generation canceled"
        End
    End If
    'Update the progress bar
    pb.CurrentCounter = i
    s.Value(i,1) = Rnd(1)
    s.Value(i,2) = RndNormal(1)
    Next i
    'Close the progress bar
    Set pb = Nothing
    'Set the variable names
    s.VariableName(1) = "Uniform"
    s.VariableName(2) = "Normal"
    s.Visible = True
End Sub