+ Reply to Thread
Results 1 to 2 of 2

Thread: Display Worksheets & Refresh Database Query

  1. #1
    Registered User
    Join Date
    04-20-2011
    Location
    Oxford, MA
    MS-Off Ver
    Excel 2003
    Posts
    1

    Display Worksheets & Refresh Database Query

    I have a excel document that has multiple metrics on multiple worksheets within the workbook. I have the code that cycles through each of the worksheets, the only problem I'm having is refreshing the database queries in the worksheet every few minutes.

    The code I have so far is below, It starts teh database connection but there's no pause for the database to update the worksheet. I'm not sure how to make it show the new database values in the sheet.

    Sub SwitchingSheets()
    Dim wSheet As Worksheet
    Dim iLoop As Integer
    Dim i As Integer

    iLoop = 2

    For i = 1 To iLoop

    For Each wSheet In Worksheets
    NewHour = Hour(Now)
    NewMinute = Minute(Now)
    NewSecond = Second(Now) + 1
    WaitTime = TimeSerial(NewHour, NewMinute, NewSecond)
    wSheet.Select
    Application.Wait WaitTime
    Next wSheet

    Next i

    Run "UpdateAll"

    End Sub
    Sub UpdateAll()

    ActiveWorkbook.RefreshAll

    Run "SwitchingSheets"

    End Sub

  2. #2
    Forum Guru Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    Excel 2010
    Posts
    1,249

    Re: Display Worksheets & Refresh Database Query

    Option Explicit
    Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    
    Sub Timer()
            ActiveWorkbook.RefreshAll
    
            Run "SwitchingSheets"
    
            Sleep 30
            Call Timer
    
    End Sub


    There is a property within the query, however, that says "Refresh every X minutes", and gives you the choice to enter the number of minutes. Are you needing something different?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0