+ Reply to Thread
Results 1 to 2 of 2

Pivot Table Variable SourceType/Data

  1. #1
    Registered User
    Join Date
    03-31-2008
    Posts
    8

    Pivot Table Variable SourceType/Data

    Hi,

    I'm trying to create a macro which has an openfiledialog that allows the user to select the appropriate excel file and have the pivot creating macro run off that file.

    However, I can't get the macro to work because the SourceData = sFile doesn't work.

    I wish to create a variable which links to an openfiledialog that will ultimately feed into the pivot table cache.

    Can anyone help me with this?

    Thank you.

    Sub GLRecoPivot2()
    '
    ' GLRecoPivot2 Macro
    ' Macro recorded 31/03/2008 by pvo2
    '

    '
    Dim sFile As String
    sFile = Application.GetOpenFilename("Text Files Only (*.txt),*.txt,All Files (*.*),*.*", 1, "Select File To Open")

    Range("A1").Select
    ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
    sFile).CreatePivotTable _
    TableDestination:="", TableName:="PivotTable4", DefaultVersion:= _
    xlPivotTableVersion10
    ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
    ActiveSheet.Cells(3, 1).Select
    With ActiveSheet.PivotTables("PivotTable4").PivotFields ("ID")
    .Orientation = xlRowField
    .Position = 1
    End With
    With ActiveSheet.PivotTables("PivotTable4").PivotFields ("SRC Value MR Sum")
    .Orientation = xlRowField
    .Position = 2
    End With
    Range("B4").Select
    ActiveSheet.PivotTables("PivotTable4").PivotFields ("SRC Value MR Sum"). _
    Orientation = xlHidden
    ActiveSheet.PivotTables("PivotTable4").AddDataFiel d ActiveSheet.PivotTables( _
    "PivotTable4").PivotFields("SRC Value MR Sum"), "Count of SRC Value MR Sum", _
    xlCount
    ActiveSheet.PivotTables("PivotTable4").AddDataFiel d ActiveSheet.PivotTables( _
    "PivotTable4").PivotFields("RDW Value MS Sum"), "Count of RDW Value MS Sum", _
    xlCount
    Range("B3").Select
    With ActiveSheet.PivotTables("PivotTable4").DataPivotFi eld
    .Orientation = xlColumnField
    .Position = 1
    End With
    Range("B4").Select
    ActiveSheet.PivotTables("PivotTable4").PivotFields ("Count of SRC Value MR Sum") _
    .Function = xlSum
    Range("C4").Select
    ActiveSheet.PivotTables("PivotTable4").PivotFields ("Count of RDW Value MS Sum") _
    .Function = xlSum
    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    08-26-2006
    Location
    -
    MS-Off Ver
    2010
    Posts
    388
    Quote Originally Posted by pvo2
    Hi,

    I'm trying to create a macro which has an openfiledialog that allows the user to select the appropriate excel file and have the pivot creating macro run off that file.

    However, I can't get the macro to work because the SourceData = sFile doesn't work.

    I wish to create a variable which links to an openfiledialog that will ultimately feed into the pivot table cache.
    Open the file first (GetOpenFilename doesn't open a file), find the used range and then set the range to the pivotcache sourcedata argument.
    Please Login or Register  to view this content.

+ Reply to Thread

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