Results 1 to 15 of 15

Create Pivot Table: Cannot Open Pivot Table Source File

Threaded View

  1. #1
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,083

    Create Pivot Table: Cannot Open Pivot Table Source File

    I'm trying to write a macro that will create a pivot table, and am getting an Error code 1004: Cannot Open Pivot Table Source File "Sheetname". My code is below. I've tried to note what each section does, and it all seems to work well except for the Pivot Table creation. Please advise.
    Sub Step_5ab()
    
     Dim DstWkb As Workbook
      Dim SrcWkb As Workbook
      Dim Rng As Range, Dn As Range, n As Integer
      Dim RngEnd As Range
      Dim Pt As PivotTable
      Dim strField As String
    
      Set Rng = Selection
      
      With Application
            .ScreenUpdating = False
            .EnableEvents = False
      End With
        
        Set DstWkb = Workbooks("NewDirection.xls")
        Set SrcWkb = Workbooks("ESS.xls")
        
        
        DstWkb.Activate
            
      'Copy and paste the Procedure - Okay
        Sheets("Sheet1").Range("A254").EntireRow.Copy
        Sheets("Results").Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
      
      SrcWkb.Worksheets("FY 10 by PAC").Activate
    
        'Copy and paste all of the ESS data -Okay
            Range("A1:N144").Copy _
                    Destination:=DstWkb.Worksheets("Results").Range("A65536").End(xlUp).Offset(1, 0)
              
       'Copy and paste a blank row - Okay
         DstWkb.Worksheets("Sheet1").Range("A272").Copy
         DstWkb.Worksheets("Results").Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        
        'Create pivot for APR Data-Here's the problem
        
        ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
            "APRData!C1:C23").CreatePivotTable TableDestination:="", TableName:= _
            "PivotTable1", DefaultVersion:=xlPivotTableVersion10
        ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
        ActiveSheet.Cells(3, 1).Select
        ActiveSheet.PivotTables("PivotTable1").AddFields RowFields:=Array("PAC", _
            "Job Title", "Unit")
        ActiveSheet.PivotTables("PivotTable1").PivotFields("FTE").Orientation = _
            xlDataField
        ActiveWorkbook.ShowPivotTableFieldList = True
        Range("C4").Select
        With ActiveSheet.PivotTables("PivotTable1").PivotFields("Unit")
            .Orientation = xlColumnField
            .Position = 1
        End With
    
        
        'Label, copy, and paste
        
         'Copy only the filtered data
               Range("A1").Activate
            Rng.SpecialCells(xlCellTypeVisible).Copy _
                    Destination:=DstWkb.Worksheets("Results").Range("A65536").End(xlUp).Offset(1, 0)
                    
                  
        'Copy and paste the Solution
            Sheets("Sheet1").Range("A265").EntireRow.Copy
            Sheets("Results").Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        
        'Copy two blank rows
         Sheets("Sheet1").Range("A272:A273").Copy
         Sheets("Results").Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
                    
        With Application
            .ScreenUpdating = True
            .EnableEvents = True
        End With
              
            'Alert the user on progress
            MsgBox "Step 5 Compare FTE Position totals to ESS is complete; the results have been recorded"
              Run "Step_6a"
    
    End Sub
    Last edited by jomili; 01-06-2010 at 09:13 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1