Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Jul 2002
    Location
    Edison, New Jersey, USA
    Posts
    215
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Percent Complete (Word 97)

    I have a request to add a message box that displays the % complete of a long running conversion macro. I already give them a msgbox saying that the macro will take a few minutes and that the keybaord will be disabled during the process. Is there an easy answer to this coding?

  2. #2
    5 Star Lounger
    Join Date
    Dec 2000
    Location
    Reading/Swindon, Berkshire, United Kingdom
    Posts
    664
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Percent Complete (Word 97)

    I thought Chip had an answer to this but I can't find it. However, J-Walk does. Whether it's as easy as you want is up to you.

    Can anyone out there confirm the existance of a Chip article?

    [edited 2 mins later]

    I know these are excel sites but I guess not too much will need changing.

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

    Re: Percent Complete (Word 97)

    Hi,

    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"
    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. These lines update the status bar.

    Cheers
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  4. #4
    3 Star Lounger
    Join Date
    Jul 2002
    Location
    Edison, New Jersey, USA
    Posts
    215
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Re: Percent Complete (Word 97)

    oooooh, will play with this, sounds GOOD!

Posting Permissions

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