sararose27
New Member
- Joined
- Aug 20, 2018
- Messages
- 8
I am on a new laptop so maybe something needs to change so the macro can be used when I change laptops or provide to others.
The marco is used to create a pivot table based on data downloaded from PeopleSoft. The name of the file will always be different.
It's a bit different pivot table because I want the text where it would normally be numbers.
I found out how to do that using this link - Pivot Table With Text in Values Area
Thanks in advance for your help.
I'm getting the error above at this section of the code:
ActiveWorkbook.PivotCaches.Create(SourceType:=xlExternal, SourceData:= _
ActiveWorkbook.Connections( _
"WorksheetConnection_ActiveSheet!Table1"), Version _
:=8).CreatePivotTable TableDestination:="Sheet2!R3C1", TableName:= _
"PivotTable3", DefaultVersion:=8
The full code:
Sub Master_Contact_List()
'
' Master_Contact_List Macro
Dim MasterContactList As Workbook
Set MasterContactList = ActiveWorkbook
Dim ws As Worksheet
Dim rg As Range
Set rg = ActiveCell.CurrentRegion
Set ws = rg.Parent
Rows("1:1").Select
Selection.Delete Shift:=xlUp
Range("A1").Select
Application.CutCopyMode = False
ws.ListObjects.Add(xlSrcRange, rg, , xlYes).Name = _
"Table1"
Range("Table1[#All]").Select
Application.CutCopyMode = False
ActiveWorkbook.Connections.Add2 _
"WorksheetConnection_ActiveSheet!Table1", "", _
"WORKSHEET; ActiveSheet" _
, "sheet1!Table1", 7, True, False
Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlExternal, SourceData:= _
ActiveWorkbook.Connections( _
"WorksheetConnection_ActiveSheet!Table1"), Version _
:=8).CreatePivotTable TableDestination:="Sheet2!R3C1", TableName:= _
"PivotTable3", DefaultVersion:=8
Sheets("Sheet2").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable3")
.ColumnGrand = False
.HasAutoFormat = True
.DisplayErrorString = False
.DisplayNullString = True
.EnableDrilldown = True
.ErrorString = ""
.MergeLabels = False
.NullString = ""
.PageFieldOrder = 2
.PageFieldWrapCount = 0
.PreserveFormatting = True
.RowGrand = False
.PrintTitles = False
.RepeatItemsOnEachPrintedPage = True
.TotalsAnnotation = True
.CompactRowIndent = 1
.VisualTotals = False
.InGridDropZones = False
.DisplayFieldCaptions = True
.DisplayMemberPropertyTooltips = True
.DisplayContextTooltips = True
.ShowDrillIndicators = True
.PrintDrillIndicators = False
.DisplayEmptyRow = False
.DisplayEmptyColumn = False
.AllowMultipleFilters = False
.SortUsingCustomLists = True
.DisplayImmediateItems = True
.ViewCalculatedMembers = True
.FieldListSortAscending = False
.ShowValuesRow = False
.CalculatedMembersInFilters = True
.RowAxisLayout xlCompactRow
End With
ActiveSheet.PivotTables("PivotTable3").PivotCache.RefreshOnFileOpen = False
ActiveSheet.PivotTables("PivotTable3").RepeatAllLabels xlRepeatLabels
With ActiveSheet.PivotTables("PivotTable3").CubeFields("[Table1].[BU]")
.Orientation = xlRowField
.Position = 1
End With
ActiveWorkbook.Model.ModelMeasures.Add "HREmail", ActiveWorkbook.Model. _
ModelTables("Table1"), "CONCATENATEX(Table1,Table1,"", "")", _
ActiveWorkbook.Model.ModelFormatGeneral
ActiveSheet.PivotTables("PivotTable3").AddDataField ActiveSheet.PivotTables( _
"PivotTable3").CubeFields("[Measures].[HREmail]")
End Sub
The marco is used to create a pivot table based on data downloaded from PeopleSoft. The name of the file will always be different.
It's a bit different pivot table because I want the text where it would normally be numbers.
I found out how to do that using this link - Pivot Table With Text in Values Area
Thanks in advance for your help.
I'm getting the error above at this section of the code:
ActiveWorkbook.PivotCaches.Create(SourceType:=xlExternal, SourceData:= _
ActiveWorkbook.Connections( _
"WorksheetConnection_ActiveSheet!Table1"), Version _
:=8).CreatePivotTable TableDestination:="Sheet2!R3C1", TableName:= _
"PivotTable3", DefaultVersion:=8
The full code:
Sub Master_Contact_List()
'
' Master_Contact_List Macro
Dim MasterContactList As Workbook
Set MasterContactList = ActiveWorkbook
Dim ws As Worksheet
Dim rg As Range
Set rg = ActiveCell.CurrentRegion
Set ws = rg.Parent
Rows("1:1").Select
Selection.Delete Shift:=xlUp
Range("A1").Select
Application.CutCopyMode = False
ws.ListObjects.Add(xlSrcRange, rg, , xlYes).Name = _
"Table1"
Range("Table1[#All]").Select
Application.CutCopyMode = False
ActiveWorkbook.Connections.Add2 _
"WorksheetConnection_ActiveSheet!Table1", "", _
"WORKSHEET; ActiveSheet" _
, "sheet1!Table1", 7, True, False
Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlExternal, SourceData:= _
ActiveWorkbook.Connections( _
"WorksheetConnection_ActiveSheet!Table1"), Version _
:=8).CreatePivotTable TableDestination:="Sheet2!R3C1", TableName:= _
"PivotTable3", DefaultVersion:=8
Sheets("Sheet2").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable3")
.ColumnGrand = False
.HasAutoFormat = True
.DisplayErrorString = False
.DisplayNullString = True
.EnableDrilldown = True
.ErrorString = ""
.MergeLabels = False
.NullString = ""
.PageFieldOrder = 2
.PageFieldWrapCount = 0
.PreserveFormatting = True
.RowGrand = False
.PrintTitles = False
.RepeatItemsOnEachPrintedPage = True
.TotalsAnnotation = True
.CompactRowIndent = 1
.VisualTotals = False
.InGridDropZones = False
.DisplayFieldCaptions = True
.DisplayMemberPropertyTooltips = True
.DisplayContextTooltips = True
.ShowDrillIndicators = True
.PrintDrillIndicators = False
.DisplayEmptyRow = False
.DisplayEmptyColumn = False
.AllowMultipleFilters = False
.SortUsingCustomLists = True
.DisplayImmediateItems = True
.ViewCalculatedMembers = True
.FieldListSortAscending = False
.ShowValuesRow = False
.CalculatedMembersInFilters = True
.RowAxisLayout xlCompactRow
End With
ActiveSheet.PivotTables("PivotTable3").PivotCache.RefreshOnFileOpen = False
ActiveSheet.PivotTables("PivotTable3").RepeatAllLabels xlRepeatLabels
With ActiveSheet.PivotTables("PivotTable3").CubeFields("[Table1].[BU]")
.Orientation = xlRowField
.Position = 1
End With
ActiveWorkbook.Model.ModelMeasures.Add "HREmail", ActiveWorkbook.Model. _
ModelTables("Table1"), "CONCATENATEX(Table1,Table1,"", "")", _
ActiveWorkbook.Model.ModelFormatGeneral
ActiveSheet.PivotTables("PivotTable3").AddDataField ActiveSheet.PivotTables( _
"PivotTable3").CubeFields("[Measures].[HREmail]")
End Sub