+ Reply to Thread
Results 1 to 3 of 3

Auto Open file VBA Refresh MS Query Save Close

  1. #1
    Registered User
    Join Date
    09-23-2005
    Posts
    1

    Auto Open file VBA Refresh MS Query Save Close

    I have made a MS Query in Excel that queries a DB and puts the info into excel. Is there code so that if I schedule the file to open the code will let the query to refresh and save and close the file?

    Now we are having an employee open the file click enable auto refresh and save and close the file.

    Thanks,
    Greg
    Impulse Manufacturing

  2. #2
    Registered User
    Join Date
    08-23-2005
    Posts
    16
    Greg
    Try something like this (you'll have to change it for your setup - easiest way will be to record a macro then refresh your query then stop and paste the code)

    put this in the 'ThisWorkbook' class module:

    Private Sub Workbook_Open()
    Sheet1.QueryTables(1).Refresh
    Me.Save
    Me.Close savechanges:=False
    End Sub

    note the workbook closes before the code finishes which isn't very elegant, but it gets the job done.


    cheers
    Simon

  3. #3
    Vacation's Over
    Guest

    Re: Auto Open file VBA Refresh MS Query Save Close

    HEY, if you put worksheet.close code in teh worksheet open sub.......

    The only way to open the file for viewing os to disable macros when asked at
    open.

    "Simon Murphy" wrote:

    >
    > Greg
    > Try something like this (you'll have to change it for your setup -
    > easiest way will be to record a macro then refresh your query then stop
    > and paste the code)
    >
    > put this in the 'ThisWorkbook' class module:
    >
    > Private Sub Workbook_Open()
    > Sheet1.QueryTables(1).Refresh
    > Me.Save
    > Me.Close savechanges:=False
    > End Sub
    >
    > note the workbook closes before the code finishes which isn't very
    > elegant, but it gets the job done.
    >
    >
    > cheers
    > Simon
    >
    >
    > --
    > Simon Murphy
    > ------------------------------------------------------------------------
    > Simon Murphy's Profile: http://www.excelforum.com/member.php...o&userid=26538
    > View this thread: http://www.excelforum.com/showthread...hreadid=470298
    >
    >


+ 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