Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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:=xlDatab ase, 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:=xlDatab ase, 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 -- ymeya ----------------------------------------------------------------------- ymeyaw's Profile: http://www.excelforum.com/member.php...fo&userid=3442 View this thread: http://www.excelforum.com/showthread.php?threadid=55593 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable | Excel Discussion (Misc queries) | |||
Pivot Table Run Time Error 1004 | Excel Programming | |||
pivot table Commandtext causes runtime error 1004 in excel 2000 | Excel Programming | |||
Pivot Table Error 1004 | Excel Programming |