Results 1 to 6 of 6
  1. #1
    New Lounger
    Join Date
    Oct 2002
    Location
    St. Paul, Minnesota, USA
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Progress indicator available? (Word 97 SR2)

    I have a big contract-generation macro that takes a couple of minutes to run and would like to add a progress indicator to show the user where s/he is in the process. Can this be done in Word97 VBA?
    Deb Jensen
    Metropolitan Council, St Paul, MN USA

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Progress indicator available? (Word 97 SR2)

    You can get custom controls that do this or just put a label control on a userform and resize (with the .width property) as your code executes.

    A very crude example is attached. Rename the file to userform.frm, then import it into a project in the VBA editor.
    Attached Files Attached Files
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Progress indicator available? (Word 97 SR2)

    You can use the Windows progress bar, which you access via an API call. If you have never used the WinAPI in VBA before, the critical thing is to find absolutely solid examples, because feeding the wrong information to Windows may have bad results for your application. Anyway, the following looks to be a good place to start:

    Creating a Common Control Progress Bar via API

    There are several linked articles that seem to relate to the subject and provide more information. I guess it's a confusing area. Nevertheless, hope this helps.

  4. #4
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Progress indicator available? (Word 97 SR2)

    Hi All
    Does anybody have a good solid example of a Progress Bar implemented in VBA? At my level of competence; to say "It's a confusing area." is a substantial understatement.
    Regards
    Don

  5. #5
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: Progress indicator available? (Word 97 SR2)

    Hi Don,

    Take a look at: http://j-walk.com/ss/excel/tips/tip34.htm
    Although for Excel, the principle is the same in Word.

    Another way of giving feedback is by updating the status bar. Before you can give the user feedback on the % complete, you'll need some sort of counter to keep track of where your macro's up to, plus a number representing whatever the counter will be at once you reach 100%. This wouldn't be practical with a simple find/replace function in a Word document, since you may not know how many such operations there'd be in a given document. In an Excel worksheet, though, the count could be based on the number of cells to be processed (eg rows*columns). Also, your various routines may each take different periods to perform a given action, so you might need to weight them differently.
    Once you've dealt with those issues, you'll find the easiest way to give status updates is by placing a message on the application's status bar. To do this:

    1 Prefix your code with:
    Option Explicit
    Dim SBar As Integer
    This stores the current state of the status bar so that it can be restored after your code has finished.

    2 Call the following MacroEntry and MacroExit subs from the first and last lines of your macro, both for feedback and maximum execution speed:
    Sub MacroEntry()
    SBar = Application.DisplayStatusBar
    Application.DisplayStatusBar = True
    Application.ScreenUpdating = False
    End Sub

    Sub MacroExit()
    Application.StatusBar = False
    Application.DisplayStatusBar = SBar
    Application.ScreenUpdating = True
    End Sub

    3 In the body of your macro, where all the work's being done, insert lines like:
    CurrentCount = CurrentCount +1
    and
    Application.StatusBar = Int(CurrentCount / TotalCount * 100) & "% Complete"
    or
    Application.StatusBar = "Processing Record " & CurrentCount
    where "CurrentCount" and "TotalCount" are the names of the counter that keeps track of where your macro's up to and the number representing whatever the counter will be at once you reach 100%, respectively. The second form is more useful when you don
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  6. #6
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Progress indicator available? (Word 97 SR2)

    Thanks a million. That is just what I was after. <img src=/S/cloud9.gif border=0 alt=cloud9 width=25 height=23>
    Regards
    Don

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •