Page 1 of 3 123 LastLast
Results 1 to 15 of 38
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Is there are a VBA pause function/statement?

    HI ya

    I need my code to pause for 5 seconds.
    I remember when one first becomes a developer they get you to write a simple bit of code that pauses & does a count down for 5 10 seconds.

    Is there a VBA function or syntax to make application/code pause for a certain amount of time?
    TIA Diana

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Is there are a VBA pause function/statement?

    Diana

    The following line of code should cause a pause for 5 seconds. Yoy can alter the duration by changing the value passed to TimeValue<pre> Application.Wait Now() + TimeValue("00:00:05")</pre>


    Andrew C

  3. #3
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Is there are a VBA pause function/statement?

    Hmm, looks like that one is available in Excel but not in Word; darn shame....

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Is there are a VBA pause function/statement?

    Yes, sorry I did not realise it was unavailable in Word, a strange omission.

    Andrew

  5. #5
    Plutonium Lounger Leif's Avatar
    Join Date
    Dec 2000
    Location
    U.K.
    Posts
    14,010
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Is there are a VBA pause function/statement?

    Based on what the above have offered:
    <pre>WaitUntil = Now() + TimeValue("00:00:05")
    Do While Now < WaitUntil
    Loop
    </pre>

    seems to work in both.

  6. #6
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Is there are a VBA pause function/statement?

    Take a look at the OnTime method. You can use it to schedule another macro to run at some time in the future. At the place where you need to pause, just put an OnTime to schedule the remaining code, in another macro, to start in 5 seconds.
    Legare Coleman

  7. #7
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Is there are a VBA pause function/statement?

    Hi Andrew,

    No need for you to be sorry, you didn't build the object model! <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15>

    Seriously, as Word-centric as my worldview is, I appreciate finding out about these things outside my purview.

    It would probably be interesting to try to put together a list of all of the functions that are available in one application, but not others. My favorite Word-only example is the Tasks method.

    The reasons for why these things ended up being available in one app, and not another, would probably make for some interesting stories, could we but know them.

    Gary

  8. #8
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Is there are a VBA pause function/statement?

    ** Geoff W Long line in "pre" tags split ***

    Another one, or two:

    You can get the GUID for Access visd VBA, but you cannot get the Product ID via Access, so you can use Word to get the Product ID via Automation from Access, e.g.:

    <pre>Option Compare Database
    Option Explicit

    Private Sub GetPID()
    Dim strProductID As String
    Dim strAssignedUserName As String
    Dim strAssignedOrganization As String
    Dim strGUID As String
    Dim wdApp As Word.Application
    strGUID = Application.ProductCode
    Set wdApp = New Word.Application
    With wdApp
    With .Dialogs(wdDialogHelpAbout)
    strProductID = RTrim$(.APPSERIALNUMBER)
    strAssignedUserName = RTrim$(.APPUSERNAME)
    strAssignedOrganization = RTrim$(.APPORGANIZATION)
    End With
    End With
    MsgBox strGUID & vbCr & strProductID & vbCr & strAssignedUserName & _
    vbCr & strAssignedOrganization
    wdApp.Quit
    Set wdApp = Nothing
    End Sub
    </pre>


    I've seen folkes use Excel to sort an array, when they could just as well have used WordBasic.SortArray.

    Etc.

  9. #9
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re:I think I actually need timer code or statement

    I've used this code but unfortunately it doesnt satisfy my requirements.
    When I use these statements it stops the application & therefore impacts on what I'm doing.

    what I want to do is a loop
    check if a file is free ie completed its execution
    if not free
    do something else for 5 seconds &
    then check if a file is free

    What I need is some timer code or counter.
    Does anyone have code that does this?

    thanks in advance Diana

  10. #10
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re:I think I actually need timer code or statement

    Diana,

    I copied thr following code from the Help (Timer) and it seesm to work on Word ok.

    Dim PauseTime, Start, Finish, TotalTime
    If (MsgBox("Press Yes to pause for 5 seconds", 4)) = vbYes Then
    PauseTime = 5 ' Set duration.
    Start = Timer ' Set start time.
    Do While Timer < Start + PauseTime
    DoEvents ' Yield to other processes.
    Loop
    Finish = Timer ' Set end time.
    TotalTime = Finish - Start ' Calculate total time.
    MsgBox "Paused for " & TotalTime & " seconds"
    Else
    End
    End If

    Can you adapt it to do what you want ?

    Andrew C

  11. #11
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re:I think I actually need timer code or statement

    HI Andrew

    I've tried code - but it doesnt resolve what I'm attempting to do.

    What I'm doing is sending the current file to printer driver (this is how we create pdf files)
    The file spools to printer
    when I use the timer code - it actually pauses & stops the file being sent to the printer
    & then when timer ends - then the rest of the file is sent to printer.
    The problem is I attempt to delete or kill file but it is still open & being used by app. & I get a run time error message - file sharing access.

    What I want to do is send file tio printer - when completed spooling - this means the file is free & I can then delete the file using 'kill' statement.

    I thought a way to solve - while file is being sent to printer - do something else for a number of seconds
    - then check if file is free
    - if file still not free -
    loop until file is free.
    Once file free - delete file.

    Do you have any ideas on how I can do this? thanks Diana

  12. #12
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re:I think I actually need timer code or statement

    I think that the only way you are going to be able to get this to work is to use the OnTime method to schedule a second macro to run at the desired time interval in the future and then exit from the current macro. The second macro can then pick up doing what you want to do after the pause.
    Legare Coleman

  13. #13
    winter
    Guest

    Re: Is there are a VBA pause function/statement?

    Yes. You can call the standard Win API Sleep(milliseconds) function.

    First declare it at the top of your code, then call it from a function.

    <pre>Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds as Long)

    Sub TestPause
    Call Sleep(5000)
    msgbox "I awake, after five seconds ..."
    End Sub</pre>


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

    Re:I think I actually need timer code or statement

    Diana,

    Did you ever get this resolved? I have an idea if you are still looking...
    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>

  15. #15
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re:I think I actually need timer code or statement

    Kevin - no I didnt get this resolved (see post from me to Andrew)
    Whats your idea?.....Please let me know - I'll have a go to resolve - regards Diana


    Andrew
    I've tried code - but it doesnt resolve what I'm attempting to do.

    What I'm doing is sending the current file to printer driver (this is how we create pdf files)
    The file spools to printer
    when I use the timer code - it actually pauses & stops the file being sent to the printer -
    therefores pauses the file being sent/spooled to printer.
    & then when timer ends - then the rest of the file is released & sent to printer.
    The problem is I attempt to delete or kill file but it is still open & being used by app. & I get a run time error message - file sharing access.

    What I want to do is send file tio printer - when completed spooling - this means the file is free & I can then delete the file using 'kill' statement.

    I thought a way to solve - while file is being sent to printer - do something else for a number of seconds
    - then check if file is free
    - if file still not free -
    loop until file is free.
    Once file free - delete file.

    Do you have any ideas on how I can do this? thanks Diana

Page 1 of 3 123 LastLast

Posting Permissions

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