Results 1 to 4 of 4
  1. #1
    sk88 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2011
    Posts
    183

    export pivot table view to excel


    so I have this code for exporting all my other queries
    Code:
    Private Sub Command4_Click()
      On Error GoTo Err_cmdTest_Click
      'Must 1st set a Reference to the Microsoft Office XX.X Object Library
      Dim dlgOpen As FileDialog
      Dim strExportPath As String
      Const conOBJECT_TO_EXPORT As String = "qryGEM"
       
      Set dlgOpen = Application.FileDialog(msoFileDialogFolderPicker)
       
      With dlgOpen
        .ButtonName = "Export To"
        .InitialView = msoFileDialogViewLargeIcons
        .InitialFileName = CurrentProject.Path
           If .Show = -1 Then
             'Allow for Root Directory selection: C:\, D:\, etc.
             strExportPath = Replace(.SelectedItems(1) & "\", "\\", "\")
       Call DoCmd.TransferSpreadsheet(TransferType:=acExport, _
                                     TableName:=conOBJECT_TO_EXPORT, _
                                     FileName:=strExportPath & conOBJECT_TO_EXPORT & ".xls")
                              
        Call DoCmd.TransferSpreadsheet(TransferType:=acExport, _
                                     TableName:="qryPivot", _
                                     FileName:=strExportPath & conOBJECT_TO_EXPORT & ".xls")
               Call DoCmd.TransferSpreadsheet(TransferType:=acExport, _
                                     TableName:="qryPresentingProblem", _
                                     FileName:=strExportPath & conOBJECT_TO_EXPORT & ".xls")
       
             MsgBox "[" & conOBJECT_TO_EXPORT & "] has been Exported to " & strExportPath & _
                     conOBJECT_TO_EXPORT & ".xls", vbInformation, "Export Complete"
           End If
      End With
       
      'Set the Object Variable to Nothing.
      Set dlgOpen = Nothing
       
      Exit_cmdTest_Click:
        Exit Sub
       
      Err_cmdTest_Click:
        MsgBox Err.Description, vbExclamation, "Error in cmdTest_Click()"
          Resume Exit_cmdTest_Click
      End Sub

    The codes work perfectly fine but it doesnt work well for pivot table view.

    What should I add to the add to make it work? I dont want pivot table in datasheet.

    I did try the codes posted by other people but it works well for if I have only ONE QUERY to export. As you can see, the above codes are for exporting more than one query.

    Thank you...

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    sk88 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2011
    Posts
    183
    Quote Originally Posted by June7 View Post

    Thanks June!

    I managed to get Pivot tables to export but it won't export more than 1 pivot tables...
    I used the below codes for exporting one pivot table and it works perfectly fine.

    Code:
    Private Sub Command0_Click()
    
    DoCmd.OpenQuery "qryProblem", acViewPivotTable, acEdit
    DoCmd.RunCommand acCmdPivotTableExportToExcel
    DoCmd.Close acQuery, "qryProblem"
    
    
    
    End Sub

    I have more than one pivot tables and queries.. How do I go about this?
    Can I somehow combine the codes with my first post codes?

    thanks!

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Did you repeat the code for each query? Why won't export more than one pivot table? Error message, wrong results, nothing happens?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 12-18-2011, 01:28 AM
  2. Query default to Pivot Table view
    By Theremin_Ohio in forum Access
    Replies: 1
    Last Post: 03-30-2011, 09:17 AM
  3. Export Access '07 Pivot Tbl to Excel'07
    By nagiese in forum Import/Export Data
    Replies: 1
    Last Post: 02-08-2011, 08:19 AM
  4. Export Pivot table to Excel Error
    By Whalen16 in forum Import/Export Data
    Replies: 3
    Last Post: 09-30-2010, 12:54 PM
  5. Export Access Pivot Table to Excel
    By graviz in forum Programming
    Replies: 1
    Last Post: 11-13-2009, 07:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums