I have a userform with a progress bar. Any ideas why the progress bar is showing the count, rather than % complete? In this instance there are 20 items, and as the progress bar runs, it starts at 1%, 2%, ending at 20%, rather than 100% (total count of the items is 20).
Sub CreateFromTemplate ()
Dim doc As Word.Document
wd.Visible = False
Dim DocumentRange As Range
'/// PROGRESS BAR:
Dim DocumentTotal As Integer
Dim Counter As Integer
Dim PctDone As Single
'///
Range("A11").Select
Set DocumentRange = Range( _
ActiveCell, _
ActiveCell.End(xlDown))
'/// PROGRESS BAR: Initialize variables
Counter = 0
DocumentTotal = Selection.Cells.Count
'///
For Each DocumentCell In DocumentRange
Set doc = wd.Documents.Open(FilePath & "Template1.docx")
CopyCell "Bookmark1", 3
CopyCell "Bookmark2", 4
CopyCell "Bookmark3", 5
CopyCell "Bookmark4", 6
CopyCell "Bookmark5", 7
CopyCell "Bookmark6", 8
doc.SaveAs2 FilePath & "Document " & DocumentCell.Value & ".docx"
doc.Close
'/// PROGRESS BAR:
Counter = Counter + 1
PctDone = Counter / DocumentTotal
With DocumentModule
.FrameProgress.Caption = Format(PctDone / 100, "0%")
.ProgressBarBox.Width = PctDone * (.FrameProgress.Width - 10)
End With
DoEvents
'///
Next DocumentCell
wd.Quit
'/// PROGRESS BAR:
With DocumentModule
.ProgressBarBox.Width = 0
.FrameProgress.Caption = "Progress Indicator"
End With
'///
MsgBox "Created files in " & FilePath, vbInformation, "Document Generator"
End Sub
Bookmarks