I
Isa
Hi,
I have this code to create a pivot table in Excel from Access.
I borrowed from another database and it works, but when i run the code on
the new database i get the error message:
Run-time error '424'
Object required
The code is as below:
Dim xlApp, wBook, sSheet As Object
Dim sql As String
Dim A As Variant
Dim var As Variant
Dim C() As Variant
Dim i, j, l, k As Integer
Dim DateTest As Date
Dim iCell As Integer
Dim sFile As String
Dim qdf
Dim ptcache As Object
DoCmd.SetWarnings False
Set xlApp = CreateObject("excel.application")
xlApp.SheetsInNewWorkbook = 1 'enter your numsheets here
Set wBook = xlApp.Workbooks.Add
xlApp.Sheets("sheet1").Name = "Volume"
EXCEL_FILE = "C:\Stock Reporting Volume" & "_" & FormatDateTime(Date -
Weekday(Date) + 7, vbLongDate) & ".xls"
sFile = Dir(EXCEL_FILE)
If sFile <> "" Then
Kill EXCEL_FILE
wBook.SaveAs EXCEL_FILE
xlApp.Visible = True
Else
wBook.SaveAs EXCEL_FILE
xlApp.Visible = True
End If
Set sSheet = wBook.Worksheets(1)
DoCmd.OpenQuery "qry_Stock_Volume_Combined", acViewNormal
RunCommand acCmdSelectAllRecords
RunCommand acCmdCopy
DoCmd.Close acQuery, "qry_Stock_Volume"
sSheet.Paste sSheet.Cells(1, 1)
Set sSheet = wBook.Worksheets(1)
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase,
SourceData:="Volume!R1C1:R20C10").CreatePivotTable TableDestination:="",
TableName:="PivotOverall"
Can anyone help?
Thanks.
I have this code to create a pivot table in Excel from Access.
I borrowed from another database and it works, but when i run the code on
the new database i get the error message:
Run-time error '424'
Object required
The code is as below:
Dim xlApp, wBook, sSheet As Object
Dim sql As String
Dim A As Variant
Dim var As Variant
Dim C() As Variant
Dim i, j, l, k As Integer
Dim DateTest As Date
Dim iCell As Integer
Dim sFile As String
Dim qdf
Dim ptcache As Object
DoCmd.SetWarnings False
Set xlApp = CreateObject("excel.application")
xlApp.SheetsInNewWorkbook = 1 'enter your numsheets here
Set wBook = xlApp.Workbooks.Add
xlApp.Sheets("sheet1").Name = "Volume"
EXCEL_FILE = "C:\Stock Reporting Volume" & "_" & FormatDateTime(Date -
Weekday(Date) + 7, vbLongDate) & ".xls"
sFile = Dir(EXCEL_FILE)
If sFile <> "" Then
Kill EXCEL_FILE
wBook.SaveAs EXCEL_FILE
xlApp.Visible = True
Else
wBook.SaveAs EXCEL_FILE
xlApp.Visible = True
End If
Set sSheet = wBook.Worksheets(1)
DoCmd.OpenQuery "qry_Stock_Volume_Combined", acViewNormal
RunCommand acCmdSelectAllRecords
RunCommand acCmdCopy
DoCmd.Close acQuery, "qry_Stock_Volume"
sSheet.Paste sSheet.Cells(1, 1)
Set sSheet = wBook.Worksheets(1)
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase,
SourceData:="Volume!R1C1:R20C10").CreatePivotTable TableDestination:="",
TableName:="PivotOverall"
Can anyone help?
Thanks.