Refresh embedded queries automatically

tonycuban

New Member
Joined
Oct 16, 2009
Messages
11
I have a file with embedded queries which I want to save to a different location, refresh all and save the file. The refresh All does not work because the file is locked by myself.
The refresh on open, doesn't work because i must prompt the user for input so the file doesn't get refresh when is open after been saved.

Any ideas would be appreciated. it would be perfect if there is a way to refresh embedded queries in a closed file.

the code is:

Function Create_Rec_XLfile()
Dim objXL As Excel.Application, objBook As Excel.Workbook
Dim strRDATE As String, strSource As String, strDestination As String

strRDATE = Format(DLookup("[rptDate]", "SD_DATA"), "yyyymmdd")
strSource = "\\main\Excel_Templates\RecToEntries.xls"
strDestination = "\\main\2011\" & strRDATE & "_RecToEntries.xls"

If Dir(strDestination) <> "" Then Kill strDestination

FileCopy strSource, strDestination

Set objXL = CreateObject("Excel.Application")
Set objBook = objXL.Workbooks.Open(strDestination)

objBook.RefreshAll

objBook.Save
objBook.Close
objXL.Quit
Set objBook = Nothing
Set objXL = Nothing
End Function
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Forum statistics

Threads
1,224,600
Messages
6,179,834
Members
452,947
Latest member
Gerry_F

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