I hope that the code below helps. You will need to know a bit of info before
using it though. I hopefully have given you everything you need, but if not
it should be easy enough to modify.
Needed Info:
Number of files to be printed.
Progress Bar control on UserForm1 (the progress bar you already have).
Code:
Private Sub CommandButton1_Click()
Dim strFile As String 'Name of file
Dim sngStart As Single
Dim sngPauseTime As Single
Dim i As Integer
On Error GoTo err_CommandButton1_Click
UserForm1.Show True
UserForm1.ProgressBar1.Max = 15 'Hard coded to make it work.
sngPauseTime = 5 'Pause time is the same for everything so take it
out of the loops _
and only run it once
'If you can use a for loop, you don't need to have the timer except to
wait for the ShellExecute.
For i = 0 To 15 'Hard coded number to make work could be variable taken
from number to be printed.
'Shell strFile, vbHide 'Place the shellExecute function here to
printout your files one at a time.
sngStart = Timer
Do While Timer < sngStart + sngPauseTime
DoEvents 'This can go here or after 'Loop'
Loop
UserForm1.ProgressBar1.Value = i 'Sets the value equal to the
file you have just printed.
'DoEvents
Next i
Unload UserForm1 'Close modal form and return to program
Exit_CommandButton1_Click:
Exit Sub
err_CommandButton1_Click:
Resume Exit_CommandButton1_Click
End Sub
'Place code in your click event.
ProgressBar1.max = 15 'number of files to be printed can be set to a
variable, etc.
I hope that this is helpful to you. The primary thing is the use of the max
property of the progressBar.
Good Luck
Post by JEGUnfortunately I don't know how to grab the information I'm trying to
display -- the percent of files that have been sent to the printer by
ShellExecute (like 1 of 15, 2 of 15, etc). So what I've done now is ugly
but maybe someone has an improvement to offer. I just made my progress
bar in time increments so at least my program has time to pause before the
"Quit Acrobat" procedure is triggered and the user will know something is
Dim PauseTime, Start
user_print = MsgBox("The documents have been sent to the default
printer.", vbMsgBoxSetForeground)
If (user_print = vbOK) Then
UserForm1.Show
ProgressBar1.Value = 0
PauseTime = 5 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
ProgressBar1.Value = 10
PauseTime = 5 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
ProgressBar1.Value = 20
PauseTime = 5 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
ProgressBar1.Value = 30
PauseTime = 5 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
('this really continues on to ProgressBar is 100)
Else
End
End If