Excel-VBA兼容性问题

时间:2013-02-27 05:13:39

标签: vba charts excel-2007 compatibility excel-2010

我在Excel Dashboard中使用了以下语句:

HeaderTableSheet.ChartObjects("Header_BreakEvenAnalysis").Copy

它在Excel-2007上每次都能正常工作,但在Excel-2010中出现错误“应用程序定义或对象定义错误”(这也不是每次都有)

我也无法弄清楚原因。

同样的解决方案/解决办法吗?

2 个答案:

答案 0 :(得分:1)

在复制图表之前需要激活工作表(仅在Excel-2010中需要)

以下代码有效:

HeaderTableSheet.Activate
HeaderTableSheet.ChartObjects("Header_BreakEvenAnalysis").Copy

答案 1 :(得分:0)

你能试试吗?

Option Explicit

Sub yourSUB()
Dim myChart As ChartObject

'--- other codes

    For Each myChart In Sheets("SheetName").ChartObjects
      If myChart.Name = "Header_BreakEvenAnalysis" Then
        myChart.Copy 
      End If
    Next myChart

'---other codes
'---release the memory and clean up
Set myChart = Nothing
End Sub