+ Reply to Thread
Results 1 to 3 of 3

Opening, refreshing data connections, saving and closing file with VBA

  1. #1
    Registered User
    Join Date
    06-06-2013
    Location
    Mass
    MS-Off Ver
    Excel 2010
    Posts
    9

    Opening, refreshing data connections, saving and closing file with VBA

    Hi All,

    I am new(er) to VBA, and am requesting your help! I have one master excel file (a library of other excel files if you will), and I want to be able to open another excel file from the master file. The file I want to open, will refresh the query data connections, then save and close it at specified time interval. My question is, how can I do this on a 12 hour time interval and get it to loop back to the beginning and complete this process all over again? I want to do this with several files, that is why I have one master file which houses macros to do the same with other files. This is what I have for code so far:

    Sub auto_open()

    Call ScheduleDataRefresh

    End Sub
    Sub ScheduleDataRefresh()

    TimeToRun = Now + TimeValue("12:00:00")
    Application.OnTime TimeToRun, "Refresh"

    End Sub
    Sub Refresh()

    ' This subroutine refreshes the data connections for the (3)
    ' queries in this campaign dashboard.

    Workbooks.Open Filename:="H:\Data.xlsx"
    ActiveWorkbook.Connections("Query from abc").Refresh
    ActiveWorkbook.Connections("Query from 123").Refresh
    ActiveWorkbook.Connections("Query from xyz").Refresh
    ActiveWorkbook.Save
    ActiveWorkbook.Close False

    End Sub
    Sub auto_close()

    Application.OnTime TimeToRun, "Refresh", , True

    End Sub

    Also tried this with Task Scheduler, but did not have much luck. Basically this needs to refresh data connections at 6 am and 6 pm so we can use the data during the day.

    Thanks for any help,
    jtukes

  2. #2
    Registered User
    Join Date
    06-06-2013
    Location
    Mass
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Opening, refreshing data connections, saving and closing file with VBA

    The file will open, data connections will refresh, but after it closes it won't reopen again in 12 hrs

  3. #3
    Registered User
    Join Date
    06-06-2013
    Location
    Mass
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Opening, refreshing data connections, saving and closing file with VBA

    Never mind I solved this with a "Call ScheduleDataRefresh" within the "Refresh Macro".

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Data Connections : Saving history before refreshing?
    By brianlg in forum Excel General
    Replies: 0
    Last Post: 10-10-2013, 12:07 PM
  2. Opening, refreshing, saving, and closing a closed workbook
    By hootiebsc in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-18-2013, 05:22 PM
  3. Replies: 2
    Last Post: 03-04-2012, 11:58 AM
  4. [SOLVED] Opening, closing, saving in different Excel versions
    By jomili in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-01-2012, 09:43 AM
  5. Refreshing workbook connections
    By Thamizh in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-04-2010, 01:30 AM

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