Hi,
I have read a lot posts talking about this subject but i just can't get some of the replies to work. So i have decided to post my own question...
I want to export the contents of a query to a new excel file and then to run an excel macro (that formats the data - and sub totals) at the press of a command button.
So far this is the code that i have:
DoCmd.OutputTo acOutputTable, lcQueryName, acSpreadsheetTypeExcel8, strReportName, True, ""
This works but now for the bit i really cant seem to get right, i want to now run this macro code:
Cells.Select
Selection.Sort Key1:=Range("G2"), Order1:=xlAscending, Key2:=Range("F2") _
, Order2:=xlAscending, Key3:=Range("B2"), Order3:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortTextAsNumbers, DataOption3 _
:=xlSortNormal
Selection.Subtotal GroupBy:=7, Function:=xlSum, TotalList:=Array(8, 9, 10, _
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, _
37, 38, 39), Replace:=True, PageBreaks:=False, SummaryBelowData:=True
Selection.AutoFormat Format:=xlRangeAutoFormatSimple, Number:=False, Font _
:=False, Alignment:=True, Border:=True, Pattern:=False, Width:=False
So how do i do it? This is really doing my head in now!!
Thanks in advance for any ideas and suggestions.
Chris
I have read a lot posts talking about this subject but i just can't get some of the replies to work. So i have decided to post my own question...
I want to export the contents of a query to a new excel file and then to run an excel macro (that formats the data - and sub totals) at the press of a command button.
So far this is the code that i have:
DoCmd.OutputTo acOutputTable, lcQueryName, acSpreadsheetTypeExcel8, strReportName, True, ""
This works but now for the bit i really cant seem to get right, i want to now run this macro code:
Cells.Select
Selection.Sort Key1:=Range("G2"), Order1:=xlAscending, Key2:=Range("F2") _
, Order2:=xlAscending, Key3:=Range("B2"), Order3:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortTextAsNumbers, DataOption3 _
:=xlSortNormal
Selection.Subtotal GroupBy:=7, Function:=xlSum, TotalList:=Array(8, 9, 10, _
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, _
37, 38, 39), Replace:=True, PageBreaks:=False, SummaryBelowData:=True
Selection.AutoFormat Format:=xlRangeAutoFormatSimple, Number:=False, Font _
:=False, Alignment:=True, Border:=True, Pattern:=False, Width:=False
So how do i do it? This is really doing my head in now!!
Thanks in advance for any ideas and suggestions.
Chris