Donkeygirl
Technical User
I am automating an excel file by using command buttons place on an empty sheet in the file, meant as a menu. I have a macro which opens a second excel file on command button click and refreshes the queries to update the data for me. I am looking for how to save and close the second file once the repfreshing is done for all of the sheets in the second workbook. Keep in mind that the file supplemental sheets.xls is open, on command chart data.xls was opened and this is the code that refreshes the data. The only thing missing is the command to save and close chart data.xls ONCE the refreshing is done. Otherwise a message comes up that the refreshing must keep going or close and end refreshing.
I hope someone can help.
Refreshquerydatas is the macro that is run on click:
Sub Refreshquerydatas()
'
' Refreshquerydatas Macro
' refresh microsoft queries, which updates the quarterly data
'
'
ChDir "H:\is\Quarterly"
Workbooks.Open FileName:="\\CC1\SYS2\BOE\DATA\is\Quarterly\chart data.xls"
Cells.Select
Range("A1:BR1650".Activate
Selection.QueryTable.Refresh BackgroundQuery:=True
Sheets("MALE".Select
Cells.Select
Range("A1:BR1650".Activate
Selection.QueryTable.Refresh BackgroundQuery:=True
Sheets("CITY".Select
Cells.Select
Range("A1:BR1650".Activate
Selection.QueryTable.Refresh BackgroundQuery:=True
Sheets("TOWNS".Select
Cells.Select
Range("A1:BR1650".Activate
Selection.QueryTable.Refresh BackgroundQuery:=True
Sheets("FEMALE".Select
Cells.Select
Range("A1:BR1650".Activate
Selection.QueryTable.Refresh BackgroundQuery:=True
ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
Sheets("COUNTS".Select
Cells.Select
Range("A1:BR1650".Activate
End Sub
I hope someone can help.
Refreshquerydatas is the macro that is run on click:
Sub Refreshquerydatas()
'
' Refreshquerydatas Macro
' refresh microsoft queries, which updates the quarterly data
'
'
ChDir "H:\is\Quarterly"
Workbooks.Open FileName:="\\CC1\SYS2\BOE\DATA\is\Quarterly\chart data.xls"
Cells.Select
Range("A1:BR1650".Activate
Selection.QueryTable.Refresh BackgroundQuery:=True
Sheets("MALE".Select
Cells.Select
Range("A1:BR1650".Activate
Selection.QueryTable.Refresh BackgroundQuery:=True
Sheets("CITY".Select
Cells.Select
Range("A1:BR1650".Activate
Selection.QueryTable.Refresh BackgroundQuery:=True
Sheets("TOWNS".Select
Cells.Select
Range("A1:BR1650".Activate
Selection.QueryTable.Refresh BackgroundQuery:=True
Sheets("FEMALE".Select
Cells.Select
Range("A1:BR1650".Activate
Selection.QueryTable.Refresh BackgroundQuery:=True
ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
Sheets("COUNTS".Select
Cells.Select
Range("A1:BR1650".Activate
End Sub