Connecting Tech Pros Worldwide Help | Site Map

Exporting to excel

  #1  
Old July 18th, 2006, 05:55 AM
Gregc.
Guest
 
Posts: n/a
Hi

I'm trying to download a query into excel and opening it up as a pivot
table. Firstly, is this possible? This is my code thus far:

Function Export()
Dim excel As String
excel = "CONSOLIDATION_XTRACT_TOTAL"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, excel,
"C:\Documents and Settings\GregoryCh\My Documents\Test.xls"

End Function

Greg

  #2  
Old July 18th, 2006, 07:15 AM
pietlinden@hotmail.com
Guest
 
Posts: n/a

re: Exporting to excel


You could record a macro in Excel that creates the pivot table, and
then call it using automation after you transfer the data.

  #3  
Old July 18th, 2006, 09:35 AM
Gregc.
Guest
 
Posts: n/a

re: Exporting to excel



pietlinden@hotmail.com wrote:
Quote:
You could record a macro in Excel that creates the pivot table, and
then call it using automation after you transfer the data.
I'm trying to automate the process.

Greg

  #4  
Old July 18th, 2006, 01:45 PM
Ron2006
Guest
 
Posts: n/a

re: Exporting to excel


I know I did that a while back. I believe what I did was downloaded the
data, then from access, opened the spreadsheet, whent to the pivot
table tab, and issued a refresh.

I believe I made a macro in excell to show me the steps needed and then
duplicated these instructions from within Access.

Ron

  #5  
Old July 19th, 2006, 01:15 AM
Gregc.
Guest
 
Posts: n/a

re: Exporting to excel



Ron2006 wrote:
Quote:
I know I did that a while back. I believe what I did was downloaded the
data, then from access, opened the spreadsheet, whent to the pivot
table tab, and issued a refresh.
>
I believe I made a macro in excell to show me the steps needed and then
duplicated these instructions from within Access.
>
Ron
Well this is where I am at.

Function TsfrExcel()
Dim objXL As Object
Dim excel As String
Dim strFile As String

excel = "CONSOLIDATION_XTRACT_TOTAL"
strFile = "C:\Documents and Settings\gregorych\My
Documents\Test.xls"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, excel,
"C:\Documents and Settings\GregoryCh\My Documents\Test.xls"
Set objXL = CreateObject("Excel.Application")
With objXL.Application
.Visible = True
.Workbooks.Open strFile

objXL.ActiveWorkbook.PivotCaches.Add(SourceType:=x lDatabase,
SourceData:= _
"CONSOLIDATION_XTRACT_TOTAL!C1:C7").CreatePivotTab le
TableDestination:="", _
TableName:="PivotTable3", DefaultVersion:=xlPivotTableVersion10
objXL.ActiveSheet.PivotTableWizard
TableDestination:=ActiveSheet.Cells(3, 1)
objXL.ActiveSheet.Cells(3, 1).Select
objXL.ActiveSheet.PivotTables("PivotTable3").AddFi elds
RowFields:=Array( _
"Fund_Type_2", "Fund_Type", "Expenditure_Type"),
ColumnFields:="Sub Hierarchy"
With
objXL.ActiveSheet.PivotTables("PivotTable3").Pivot Fields("SumOfTotal_Budget")
.Orientation = xlDataField
.Caption = "Sum of SumOfTotal_Budget"
.Function = xlSum
End With
objXL.ActiveSheet.PivotTables("PivotTable3").Pivot Select "YHR",
xlDataAndLabel, True
With obj.Xl.ActiveSheet.PivotTables("PivotTable3").Pivo tFields("Sub
Hierarchy")
.PivotItems("(blank)").Visible = False
End With
Set objXL = Nothing
End With

End Function

At the moment I am stuck here:
objXL.ActiveWorkbook.PivotCaches.Add(SourceType:=x lDatabase,
SourceData:= _
"CONSOLIDATION_XTRACT_TOTAL!C1:C7").CreatePivotTab le
TableDestination:="", _
TableName:="PivotTable3", DefaultVersion:=xlPivotTableVersion10

Greg

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
gridview not exporting to excel Tom answers 4 December 19th, 2006 02:15 AM
Exporting to excel Kevin Humphreys answers 6 August 4th, 2006 08:15 PM
CrystalReport.NET exporting to Excel Problem Mustufa Baig answers 1 November 19th, 2005 11:53 AM
How to specify filename when exporting to EXCEL ad answers 1 November 18th, 2005 07:32 PM
How to specify Range when exporting to Excel with JET? deko answers 2 November 13th, 2005 11:56 AM