Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pivot table and database connection from vbscript

Status
Not open for further replies.

edkuse

Programmer
Jul 23, 2003
4
US
I'm trying to create a pivot table in Excel from a vbscript file. The data in the table will come from a database. I have a macro in Excel I created that works perfectly, but there's one part of the code that does not work in vbscript, and it's really got me frustrated.

When I try to assign the recordset to the PivotCache object, that's where I'm getting an error ("Unknown runtime error"). Here's the code:

....
Set xlApp = CreateObject("Excel.Application")
Set xlWkb = xlApp.Workbooks.Add
xlApp.Visible = True

Set conn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")

conn.Open "my connection string"

rs.Open "SELECT * FROM table", conn

Set pc = xlWkb.PivotCaches.Add(2) 'xlExternal

Set pc.Recordset = rs
'This is where I'm getting the error. Again, I'm having no problems when running this code from Excel. The database connection and query is fine.

Please offer any suggestions, thank you.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top