creating pivot tables in Excel from Access



Hello,
I have a problem with creating a pivot table in Excel from Access VBA.

I have wrote something like this:
.....
Dim objExcel As Object
dim vArkusz as String

Set objExcel = GetObject(, "Excel.Application")
(...)
vArkusz = "dane"
objExcel.ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase,
SourceData:= _

"objExcel.sheets(vArkusz).range(cells(1,1),cells(4,4))").CreatePivotTable
TableDestination:=objExcel.Range("A10"), _
TableName:="Tabela"
(...)

I get an error:
"Run-time error '5': Invalid procedure call or argument"

What do I do wrong?
Maybe the range (SourceData) should not look like I wrote?
Maybe there is another way to create pivot table?

I would be grateful for any help.
.......
narina

.


Quantcast