[算表] VBA建立樞紐問題

看板Office作者 (平凡幼稚鬼...)時間13年前 (2012/09/22 23:27), 編輯推噓0(006)
留言6則, 2人參與, 最新討論串1/1
軟體:EXCEL 2003 版本:NA 請教各位高手,小弟用錄製的方式建立巨集,巨集的內容為建立 樞紐分析表及圖,並設定按下commandbutton時執行此巨集,但 執行時發生錯誤"執行階段錯誤1004,class pivottable的addfiles 方法失敗",請教各位這是那裡出了問題? ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _ "summary!C1:C13").CreatePivotTable TableDestination:= _ "'[新增Microsoft Excel 工作表.xls]Sheet1'!R10C1", TableName:="樞紐分析表1", _ DefaultVersion:=xlPivotTableVersion10 **************************************************************************** ActiveSheet.PivotTables("樞紐分析表1").AddFields RowFields:="資料", ColumnFields:= _ "PM Parts", PageFields:=Array("Type", "型號")<-------顯示異常的程式 ****************************************************************************** With ActiveSheet.PivotTables("樞紐分析表1").PivotFields("PM Parts") .Orientation = xlDataField .Position = 1 End With With ActiveSheet.PivotTables("樞紐分析表1").PivotFields("電容") .Orientation = xlDataField .Position = 2 End With With ActiveSheet.PivotTables("樞紐分析表1").PivotFields("ESC") .Orientation = xlDataField .Position = 3 End With With ActiveSheet.PivotTables("樞紐分析表1").PivotFields("POWER") .Orientation = xlDataField .Position = 4 End With With ActiveSheet.PivotTables("樞紐分析表1").PivotFields("gas") .Orientation = xlDataField .Position = 5 End With With ActiveSheet.PivotTables("樞紐分析表1").PivotFields("pilot wafer iuuse") .Orientation = xlDataField .Position = 6 End With With ActiveSheet.PivotTables("樞紐分析表1").PivotFields("APC") .Orientation = xlDataField .Position = 7 End With ActiveSheet.PivotTables("樞紐分析表1").PivotFields("其它").Orientation = xlDataField Charts.Add ActiveChart.Location Where:=xlLocationAsNewSheet Sheets("Sheet1").Select End Sub -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.204.197.252

09/23 13:28, , 1F
09/23 13:28, 1F

09/23 14:25, , 2F
感謝樓上大大,已經可以了,我想你用的是在BUTTION上指定
09/23 14:25, 2F

09/23 14:26, , 3F
巨集,但很奇怪,我的BUTTON按右鍵就沒"指定巨集"這個選項
09/23 14:26, 3F

09/23 14:27, , 4F
所以我後來把你的button剪到我的file裡再改一下就可以了
09/23 14:27, 4F

09/23 14:30, , 5F
我的button是在程式端加入"Module1.Macro1",不過好像不行
09/23 14:30, 5F

09/23 14:31, , 6F
總之...謝謝啦~昨天試了好幾個小時試不出來@@
09/23 14:31, 6F
文章代碼(AID): #1GNTZRQe (Office)
文章代碼(AID): #1GNTZRQe (Office)