PDA

View Full Version : Solved: Word Progress Bar



markh1182
06-14-2007, 06:24 AM
Hi, I am using the built in progress bar on a form so that on a macro that copies large amounts of data in to a table users know where it is at. However, if you go out of Word, then back in, the form displays, but the progress bar disappears. The form is on screen in the vbModeless option.

Does anyone have any ideas on how to make sure this progress bar displays? I want users to be able to carry on working whilst this is running and be able to just check its progress.

I have tried repaint the form within the loop of the code and also refresh and setfocus of the progress bar but none had any effect.

lucas
06-14-2007, 07:54 AM
You could use the status bar and do away with the progress bar:
Sub StatusBarExample()
Application.ScreenUpdating = False
' turns off screen updating
Application.DisplayStatusBar = True
' makes sure that the statusbar is visible
Application.StatusBar = "Please wait while performing task 1..."
' add some code for task 1 that replaces the next sentence
Application.Wait Now + TimeValue("00:00:02")
Application.StatusBar = "Please wait while performing task 2..."
' add some code for task 2 that replaces the next sentence
Application.Wait Now + TimeValue("00:00:02")
Application.StatusBar = False
' gives control of the statusbar back to the programme
End Sub

markh1182
06-14-2007, 08:22 AM
Hi, thanks for the reply, however that is not too much different to what I had before. Is there a way to get this to display a % or something similar to show how long it has left? Otherwise, I need help in amending my code for the progress bar.

lucas
06-14-2007, 08:36 AM
Here's one that runs a progress bar across the status bar area with %
Public Sub TestProgessBar()
Dim x As Long
Dim n As Long


Dim f As StatusProgress 'Instantiate our status bar
Set f = New StatusProgress

With f

.MaxProgress = 500 'Maximum progress to be used

.Style = Style1 'Style for the status bar

.Color = NavyBlue 'Status color

'.BackColor = White

.BarType = Smooth ' Led / Smooth

.ProgressShow 'Show it!



For x = 1 To .MaxProgress

For n = 1 To 1000000 'These 2 lines slow the loop down
Next n 'Replace with your code here

.Progress x 'Increment progress
Next x


.ProgressFinish 'Reset the status bar
End With

Set f = Nothing 'Clear memory
End Sub

fumei
06-14-2007, 12:05 PM
Ummm, Steve? Don't you think you should mention that StatusProgress is pretty darn uselss without the class module that actually creates it?

lucas
06-14-2007, 12:10 PM
Oops...import this into your project ..I had to zip it to attach it.
Hope the poster isn't too frustrated to try it now...sorry.

markh1182
06-15-2007, 02:19 AM
The only downside to that statusprogress class is that it is aimed at Excel and not Word so therefore comes up with errors when running in Word.

I have tried to have a look through the code to see if I can amend it to fit but have been unable to do so.

Any ideas?

lucas
06-15-2007, 08:40 AM
Mark...I'm going to have to apologize because I didn't take the time to make sure these worked in Word...bad assumtion on my part. Here is one you can try that I did test in Word...let us know if it helps:
Option Explicit
Sub StatusBar()
Dim x As Integer
Dim MyTimer As Double
'Change this loop as needed.
For x = 1 To 250

'Dummy Loop here just to waste time.
'Replace this loop with your actual code.
MyTimer = Timer
Do
Loop While Timer - MyTimer < 0.03
Application.StatusBar = "Progress: " & x & " of 250: " & Format(x / 250, "Percent")
DoEvents

Next x
Application.StatusBar = False
End Sub
There are many more examples in the knowledgebase...just use the link at the top of the page....kbase and it is searchable...I used progress as a search term.

markh1182
06-20-2007, 07:32 AM
managed to get the normal progress bar working by adding in DoEvents to my loop.