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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create Pivot Table & Export to Excel in VBA

Status
Not open for further replies.

sandra45

Technical User
Apr 3, 2003
72
0
0
ID
Hi, I've been searching for websites which give some ideas on how to create pivot table and export it to Excel by using VBA. Can anybody give me reference where I can find the tutorial or guideline? Thanks.

Regards,
Sandra
 
Hi,

This is the way i go ....

Dim pPeriod As Date
Dim qdf As DAO.QueryDef
Dim strSQL As String
Dim FileName As String

pPeriod = CDate("01/" & Me.cmbMonth & "/" & Me.cmbYear)
Set dbs = CurrentDb

strSQL = "TRANSFORM statement ... "

Set qdf = dbs.CreateQueryDef("TempQry", strSQL)

If export = False Then
DoCmd.OpenQuery "TempQry", acViewNormal, acReadOnly
Else
FileName = "test"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "TempQry", FileName
End If

dbs.QueryDefs.Delete "TempQry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top