+ Reply to Thread
Results 1 to 7 of 7

Problem with wait/sleep

Hybrid View

  1. #1
    Registered User
    Join Date
    05-14-2007
    Posts
    4

    Problem with wait/sleep

    Hi all,

    I've recorded an excel macro which basically just opens up an excel file does a "Refresh All" saves and shuts itself. Problem I'm having is that the "Refesh All" command doesn't have time to finish before the macro tries moving on to the next step.

    I'd like to get my macro to sleep for X seconds so the "Refresh All" can finish.

    I am using Excel 2007.


    Here is my current macro :

    Sub Test()
    '
    ' Test Macro
    '
    
    '
        ChDir "C:\Statistiques\Traitement\Excel"
        Workbooks.Open Filename:="C:\Statistiques\Traitement\Excel\stats mails.xlsx"
        ActiveWorkbook.RefreshAll
        With ActiveWorkbook.PublishObjects("stats mails_610")
            .HtmlType = xlHtmlStatic
            .Publish (False)
            .AutoRepublish = False
        End With
        ChDir "C:\Statistiques\Statistiques"
        ActiveWorkbook.Save
        ActiveWindow.Close
        ActiveWorkbook.Save
    End Sub

    Regards,

    John Gillespie
    Last edited by johngillespie; 05-14-2007 at 08:50 AM.

  2. #2
    Registered User
    Join Date
    05-14-2007
    Posts
    4
    I have tried using this method (http://msdn2.microsoft.com/en-us/lib...ffice.11).aspx) but it pauses the Refresh all command

  3. #3
    Registered User
    Join Date
    11-16-2006
    Posts
    80
    Is this what your looking for?

    Application.Wait Now + TimeValue("00:00:05")
    The code will wait for 5 seconds.

    HTH,
    mccreaso

  4. #4
    Registered User
    Join Date
    05-14-2007
    Posts
    4
    Quote Originally Posted by mccreaso
    Is this what your looking for?

    Application.Wait Now + TimeValue("00:00:05")
    The code will wait for 5 seconds.

    HTH,
    mccreaso
    I have tried that and it doesn't work since the Refresh command gets paused too What I need is something that lets the Refresh command to run whilst pausing the rest of the macro.

  5. #5
    Registered User
    Join Date
    11-16-2006
    Posts
    80
    Split it into 2 macros and use the Application.OnTime function:

    Macro1
    Sub Test()
    
        ChDir "C:\Statistiques\Traitement\Excel"
        Workbooks.Open Filename:="C:\Statistiques\Traitement\Excel\stats mails.xlsx"
        ActiveWorkbook.RefreshAll
        With ActiveWorkbook.PublishObjects("stats mails_610")
            .HtmlType = xlHtmlStatic
            .Publish (False)
            .AutoRepublish = False
        End With
    Application.OnTime Now + TimeValue("00:00:05"), "saveDoc" 
    ' Run save macro after 5 seconds
    
    End Sub
    Macro 2

    Sub saveDoc()
        ChDir "C:\Statistiques\Statistiques"
        ActiveWorkbook.Save
        ActiveWindow.Close
        ActiveWorkbook.Save
    End Sub
    Havent tested it, but hope it helps,

    mccreaso

  6. #6
    Registered User
    Join Date
    05-14-2007
    Posts
    4
    worked like a charm, thanks a lot !

  7. #7
    Registered User
    Join Date
    11-16-2006
    Posts
    80
    Glad it helped !
    mccreaso

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1