Auto Open file VBA Refresh MS Query Save Close

G

gcutter

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

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

Thanks,
Greg
Impulse Manufacturin
 
S

Simon Murphy

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
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top