Results 1 to 11 of 11

Thread: VB & Word & Stopping

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2000
    Location
    Dublin
    Posts
    30
    I am running a VB program to open and close various MS Word documents..

    The program can take up to five minutes to complete..

    How can I leave a command button (or whatever) active on the screen to enable to me stop/break the program without having to wait for the program to complete?

    Thanks,
    Graham.

  2. #2
    Guest
    Try adding a DoEvents which I think will let you do other stuff while the program is processing.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2000
    Location
    Dublin
    Posts
    30
    Thanks but...


    I actually want to stop the program.

    Graham.

  4. #4
    Guest
    Stop it..as in exiting the application? Or the individual MS Word documents?

  5. #5
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411

    Who is in control?

    IS your application in control for this 5 minute period? OR has your program called some method on the Word Document that means you are just waiting for VB to get control again?

    If you are in control, then Matthew's suggestion means to add a DoEvents call in your main loop - someplace where it will get attention quite frequently.

    This means that any button you have on your form will have a chance at being pressed whereas normally, VB will only bother to see if the button is pressed when it has finished the current task.

    Hope it helps
    Paul Lewis

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jul 2000
    Location
    Dublin
    Posts
    30
    Stop it - as in exiting the application.

    I am selecting a sub-directory on a file server and performing functions on all Word docs found.

    Sometimes I accidentally select the wrong directory and I want to stop before it goes too far and does damage to the wrong set of sub directories i.e. Kill the application in mid program (up until now I have to use ctrl-alt-del).

    Graham.

  7. #7
    Guest
    Are you selecting them through your program?

    Because just have a confirm message come up and ask if that's the file you want to use.

    Code:
    confirm = Msgbox("Are you sure you want that file?", 4 + 32)
    If confirm = vbYes Then
    'do your code
    Else
    End If

  8. #8
    Guest
    If your code is looping, have a look at this old loop to stop the loop.

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Jul 2000
    Location
    Dublin
    Posts
    30
    Thanks for the help guys - but I'm still not getting it.

    The program is running - I just want to kill it by clicking a button or pressing a key.

    My program is looping - so I could put some code in to look for a particular key press..


    How would I look for a keypress while the program is looping?

    Graham.

  10. #10
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411

    Better explanation for you

    Since you said you're not getting it, here are the "rules" you ought to follow for now:

    1) have your VB form visible while the word processing is happening. If that is not possible, tell us why.

    2) Make an ABORT button on your app that does the following:
    2.1) Closes any open word docuemnts and then removes the word object from memory (i.e. set oWord = Nothing). Otherwise you end up with Word tasks kicking around.
    2.2) tidies up any other objects or files you had in use during the main loop.

    3) In your main loop add a statement DoEvents.

    If you do this, you will be able to make your application abort upon clicking the button.

    Let us know if you get stuck on any of these steps.

    Regards
    Paul Lewis

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Jul 2000
    Location
    Dublin
    Posts
    30
    Thanks for the help Paul,

    I'll follow that route.

    Graham.

Posting Permissions

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



Click Here to Expand Forum to Full Width