Pivot macros error 1004

Y

ymeyaw

dear all experts,

I had a macros to import all txt files from one folder and put the
into different worksheets but under one workbook. Then, i plan to us
pivot to do some processing on each worksheet.First , i tried to us
"macro record " to capture the scripts but i would have this erro
"1004, unable to get pivot tables property of the worksheet class" whe
i run the script .Can somebody point out where is problem ?



Sub ABS()
Dim varr As Variant
Dim wkbk1 As Workbook
Dim wkbk As Workbook
Dim i As Long
Dim sh1 As Worksheet
Dim sName As String

varr = Array( _
"DATA1.log", _
"DATA2.log")

Set wkbk = ActiveWorkbook
For i = LBound(varr) To UBound(varr)
Workbooks.OpenText Filename:="C:\RAWDATA\2006\" & varr(i), _
Origin:=xlWindows, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=True, Tab:=True, Semicolon:=False
Comma:=True, _
Space:=True, Other:=False, FieldInfo:=Array(Array(1, 1)
Array(2, 1), Array(3 _
, 1), Array(4, 1)), TrailingMinusNumbers:=True
Cells.Select
Cells.EntireColumn.AutoFit


Set wkbk1 = ActiveWorkbook
Set sh1 = wkbk.Worksheets.Add(after:= _
wkbk.Worksheets(wkbk.Worksheets.Count))
wkbk1.Worksheets(1).UsedRange.Copy _
Destination:=sh1.Range("A1")
sName = wkbk1.Name
sName = Left(sName, Len(sName) - 4)
wkbk1.Close SaveChanges:=False
sh1.Name = sName
Cells.Select
Cells.EntireColumn.AutoFit

Next


End Sub





Sub Macro1()
'
' Macro1 Macro

'

'
Range("H1").Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:
_
"DATA1!C1:C2").CreatePivotTable TableDestination:= _
"[test_pivot.xls]DATA1!R1C8", TableName:="PivotTable1", _
DefaultVersion:=xlPivotTableVersion10
ActiveWorkbook.ShowPivotTableFieldList = True
With ActiveSheet.PivotTables("PivotTable1").PivotFields("MO")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable1").AddDataFiel
ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("Attribute"), "Count of Attribute"
xlCount
Sheets("DATA2").Select
Range("H1").Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:
_
"DATA2!C1:C2").CreatePivotTable TableDestination:= _
"[test_pivot.xls]DATA2!R1C8", TableName:="PivotTable2", _
DefaultVersion:=xlPivotTableVersion10
With ActiveSheet.PivotTables("PivotTable2").PivotFields("MO")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable2").AddDataFiel
ActiveSheet.PivotTables( _
"PivotTable2").PivotFields("Attribute"), "Count of Attribute"
xlCount
End Su
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top