VBA code to make sheet wait and then progress without using Application.Wait???

genepaton

New Member
Joined
Jun 1, 2011
Messages
37
Hi,

Im wondering if there is VBA code to make a worksheet activate, wait for a given period and then progress to the next sheet, without using the script Application.Wait?

I need to avoid using this so that any Active X controls i have on the page can update.

I've tried playing with Application.OnTime and using another macro to advance a sheet like Sheets(ActiveSheet.Index + 1).Activate, but i can't seem to get it right.

Any help greatly appreciated.
 
This might give you some ideas on how to clean it up...

Code:
EndMacro:

    Call Worksheet_SlideShow
   
    Application.OnTime dTime1, "TestImportData"
   
End Sub

Code:
Private Sub Worksheet_SlideShow()

    Dim i As Integer, ws As Worksheet, t As Single, countdown As Integer

    For i = 4 To Sheets.Count
    
        Set ws = Sheets(i)
        ws.Activate
        t = Timer + 5   '5 second timer

        If i = 6 Then
            ActiveSheet.WebBrowser1.Navigate2 "http://www.calculatorcat.com/moon_phases_/phasenow.php?tcv=31"
            ActiveSheet.WebBrowser1.Document.Body.SetAttribute "scroll", "no"
            ws.ScrollArea = "A1:T48"
        End If


        Do While Timer < t 'Wait 5 seconds
            DoEvents ' Allows the browser to update and other events to complete

            If Int(t - Timer) + 1 <> countdown Then
                countdown = Int(t - Timer) + 1
                Application.StatusBar = "Waiting: " & countdown & " seconds" 'Status bar countdown
            End If
        Loop

    Next i
    Application.StatusBar = "Done"

End Sub
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Brilliant, thank you very much.
Code works great, and looks a lot neater.
So the Wait Timer allows things to load/you to interact with things on the page, where as the Application.Wait keeps the hourglass on screen and no interaction.

This might give you some ideas on how to clean it up...

Code:
EndMacro:

    Call Worksheet_SlideShow
   
    Application.OnTime dTime1, "TestImportData"
   
End Sub
Code:
Private Sub Worksheet_SlideShow()

    Dim i As Integer, ws As Worksheet, t As Single, countdown As Integer

    For i = 4 To Sheets.Count
    
        Set ws = Sheets(i)
        ws.Activate
        t = Timer + 5   '5 second timer

        If i = 6 Then
            ActiveSheet.WebBrowser1.Navigate2 "http://www.calculatorcat.com/moon_phases_/phasenow.php?tcv=31"
            ActiveSheet.WebBrowser1.Document.Body.SetAttribute "scroll", "no"
            ws.ScrollArea = "A1:T48"
        End If


        Do While Timer < t 'Wait 5 seconds
            DoEvents ' Allows the browser to update and other events to complete

            If Int(t - Timer) + 1 <> countdown Then
                countdown = Int(t - Timer) + 1
                Application.StatusBar = "Waiting: " & countdown & " seconds" 'Status bar countdown
            End If
        Loop

    Next i
    Application.StatusBar = "Done"

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,634
Members
452,934
Latest member
Jdsonne31

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top