返回列表 上一主題 發帖

[發問] EXCEL 2007 VBA 在EXCEL 2010 執行出問題

回復 2# li_hsien
  1. Sub w_report_Click()
  2.     '-----開啟W表單-----   
  3.     Dim program_file As String, filename As String, w_file As String   
  4.     program_file = Left(ActiveWorkbook.Name, Application.Find(".", ActiveWorkbook.Name) - 1)
  5.     filename = Application.GetOpenFilename   
  6.     On Error GoTo HandleErr  '你希望程式碼有錯誤到 HandleErr
  7.      A w_file '但執行此程序,如有錯誤會回到HandleErr,你不易偵錯的
複製代碼
  1. Sub A(w_file)
  2.     Dim this_week As Integer, end_col As Integer, end_row As Integer, i As Integer, delete_col As Integer
  3.    'w_file->W1414_GF108_CP_weekly_report
  4.    'w_file 正確為 W1414_GF108_CP_weekly_report.xls
  5.     With Workbooks(w_file).Worksheets(1)  'Workbooks(w_file)才不會出錯
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 4# li_hsien
我的是2003版,執行附檔程式碼是2003版以上版本寫的.
錯誤點都是 "不支援此屬性或方法" ,可以標出錯誤點是哪裡,看看如何解決
  1. Sub A_chart(w_file)
  2.     'Dim C As ChartObject
  3.     'Set C = Workbooks(w_file).Worksheets(1).ChartObjects("Chart 3")
  4.     With Workbooks(w_file).Worksheets(1).ChartObjects("Chart 3").Chart
  5.         '.ChartArea.Format.Line.Visible = msoFalse   '2003錯誤
  6.         .ChartArea.Border.LineStyle = msoFalse   '改成這樣對嗎?
  7.         .SizeWithWindow = True
  8.         '.ChartArea.Width = 362.5 '寬度 原1449.25      '2003錯誤
  9.         '.ChartArea.Height = 124.75  '高度 原178.75    '2003錯誤
  10.         .Parent.Width = 362.5  ' *** 這樣對嗎? ***
  11.         .Parent.Height = 124.75
  12.         
  13.         With .PlotArea
  14.             .Height = 102.148661417323 '繪圖區高度 原120.97031496063
  15.             .Width = 342.872283464567  '繪圖區寬度 原358.980866141732
  16.             .Left = 10 '繪圖區位移
  17.             .Top = 10  '繪圖區位移
  18.         End With

  19.         '圖表標題
  20.         With .ChartTitle
  21.             If IsError(Application.Find(".", Worksheets(2).Range("G2"))) = False Then
  22.                 .Text = Left(ActiveChart.ChartTitle.Text, Application.Find(" ", ActiveChart.ChartTitle.Text) - 1) _
  23.                     & "-" & Mid(Worksheets(2).Range("G2"), Application.Find(".", Worksheets(2).Range("G2"), Application.Find(".", Worksheets(2).Range("G2")) + 1) + 1, 3) _
  24.                     & " " & "wk" & Right(Worksheets(2).Range("A2"), 4) & " " & Right(ActiveChart.ChartTitle.Text, 15)
  25.             ElseIf IsError(Application.Find(".", Worksheets(2).Range("G2"))) = True Then
  26.                 .Text = Left(ActiveChart.ChartTitle.Text, Application.Find(" ", ActiveChart.ChartTitle.Text) - 1) _
  27.                     & "-" & Mid(Worksheets(2).Range("G2"), Application.Find("_", Worksheets(2).Range("G2"), Application.Find("_", Worksheets(2).Range("G2")) + 1) + 1, 3) _
  28.                     & " " & "wk" & Right(Worksheets(2).Range("A2"), 4) & " " & Right(ActiveChart.ChartTitle.Text, 15)
  29.             End If
  30.             .Font.Size = 6.5  '標題字體大小
  31.             .Font.Name = "Arial" '標題字型
  32.             .Left = 123  '標題位移
  33.         End With
  34.         With .Legend
  35.             .Position = xlLegendPositionBottom  '圖例列底部
  36.             '.Legend.Top = 300   '圖例位移
  37.             .Top = Range("A21").Top
  38.             .Font.Size = 6.5 '圖例字體大小
  39.             .Font.Name = "Arial" '圖例字型
  40.         End With
  41.         With .SeriesCollection("Yield")
  42. '            .SeriesCollection(4).Border.ColorIndex = 18 '線條顏色
  43.             .Border.Color = 5066944 '線條顏色
  44.             '.SeriesCollection("Yield").Format.Line.Weight = 1 '線條&標記寬為1
  45.             '.Format.Line 2003錯誤 ***********
  46.             .Border.Weight = 1            '.LineStyle = 0
  47.             .Border.Weight = -4138   '只改變線條
  48.             .MarkerStyle = 2  '標記菱形
  49.             .MarkerBackgroundColorIndex = 2 '標記顏色(白)
  50.             .MarkerSize = 5    '標記大小5
  51.             .MarkerForegroundColor = 5066944    '標記外框
  52.             .ApplyDataLabels  '顯示資料標籤
  53.             .DataLabels.Font.Size = 5  '上列數值字體大小
  54.             .DataLabels.Font.Name = "Arial" '上列數值字型
  55.             
  56.         End With
  57.         '.SeriesCollection("Yield").Select    '不需要
  58.        ' .SetElement (msoElementDataLabelTop) '資料標籤置上 '2003沒這選項
  59.         .Axes(xlValue, xlPrimary).AxisTitle.Font.Size = 6.5 'Y軸標題大小
  60.         .Axes(xlValue, xlPrimary).AxisTitle.Font.Name = "Arial" 'Y軸標題字型
  61.         .Axes(xlValue, xlPrimary).AxisTitle.Left = -3  'Y軸標題位移

  62.         .Axes(xlCategory).TickLabels.Font.Size = 5  'X軸字體大小
  63.         .Axes(xlCategory).TickLabels.Font.Name = "Arial"    'X軸字型
  64.         
  65.         .Axes(xlValue).TickLabels.Font.Size = 6.5  'Y軸字體大小
  66.         .Axes(xlValue).TickLabels.Font.Name = "Arial"  'Y軸字型
  67.         
  68.         .SeriesCollection("Yield").DataLabels.Font.Size = 5  '上列數值字體大小
  69.         .SeriesCollection("Yield").DataLabels.Font.Name = "Arial" '上列數值字型
  70.     End With
  71. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

本帖最後由 GBKEE 於 2014-4-25 13:25 編輯

回復 6# li_hsien
自己電腦測試有副檔名 沒副檔名都可以 (也是2003版嗎?,可以嗎?)
  1. 'Workbooks(program_file).Worksheets(1).w_file = ""  '2003這裡是錯誤的
  2.       w_file = ""  
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

本帖最後由 GBKEE 於 2014-4-25 14:51 編輯

回復 8# li_hsien
那不好意思我只有2003版幫不上忙了.需有請2010版的幫忙.
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 11# li_hsien
  1. MsgBox filename   '有副檔名的
  2. 'Dir 函數 語法 Dir [(pathname[, attributes])]
  3. w_file = Dir(filename, vbNormal)  '加 attributes這參數試試看
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 修行要繫緣修心,藉事練心,隨處養心。
返回列表 上一主題