View Single Post
 
Old 08-12-2014, 06:41 AM
gmayor's Avatar
gmayor gmayor is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

If the progress bar doesn't display anything, then clearly it is not working. The idea is that it is updated by processes in the macro that calls it. This is usually in the form of a loop, as in the example I posted earlier. You need to establish how many updates to make and then increment a counter at those update points and use the counter to calculate the value of the bar at those update points. The following example shows how to do that with 10 steps (though as the macro is a simple one, I have added delays of 1 second before each update). The macro, run from Word, does not display the document until the macro is finished.


Code:
Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub Macro1()
Dim oDoc As Document
Dim oFrm As frmProgress

    Set oDoc = Documents.Add(Visible:=False)

    Set oFrm = New frmProgress
    oFrm.Show vbModeless
    Application.ScreenUpdating = False

    UpdateBar oFrm, 1, 10
    oDoc.Range.InsertAfter "A line of text" & vbCr
    Sleep 1000        ' a one second delay
    UpdateBar oFrm, 2, 10
    oDoc.Range.InsertAfter "A line of text" & vbCr
    Sleep 1000        ' a one second delay
    UpdateBar oFrm, 3, 10
    oDoc.Range.InsertAfter "A line of text" & vbCr
    Sleep 1000        ' a one second delay
    UpdateBar oFrm, 4, 10
    oDoc.Range.InsertAfter "A line of text" & vbCr
    Sleep 1000        ' a one second delay
    UpdateBar oFrm, 5, 10
    oDoc.Range.InsertAfter "A line of text" & vbCr
    Sleep 1000        ' a one second delay
    UpdateBar oFrm, 6, 10
    oDoc.Range.InsertAfter "A line of text" & vbCr
    Sleep 1000        ' a one second delay
    UpdateBar oFrm, 7, 10
    oDoc.Range.InsertAfter "A line of text" & vbCr
    Sleep 1000        ' a one second delay
    UpdateBar oFrm, 8, 10
    oDoc.Range.InsertAfter "A line of text" & vbCr
    Sleep 1000        ' a one second delay
    UpdateBar oFrm, 9, 10
    oDoc.Range.InsertAfter "A line of text" & vbCr
    Sleep 1000        ' a one second delay
    UpdateBar oFrm, 10, 10
    oDoc.Range.InsertAfter "A line of text" & vbCr
    Unload oFrm
    oDoc.ActiveWindow.Visible = True
End Sub

Sub UpdateBar(oFrm As frmProgress, Count As Long, TotalSteps As Long)
Dim PartDone As Double

    PartDone = Count / TotalSteps
    oFrm.lblProgress.Width = oFrm.fmeProgress.Width * PartDone
    oFrm.Caption = "Processing item " & Count & " of " & TotalSteps
    DoEvents
End Sub
Reply With Quote