图表sourcedata多个范围停止工作

时间:2015-09-24 01:26:50

标签: excel excel-vba vba

我在VBA中有代码,动态设置两个图表的源数据。此代码在过去五年中一直与十个用户合作。直到今天,当有人试图在Windows 10机器上运行它并且当它达到第二个setsourcedata时得到应用程序错误1004 - 第一个工作正常。

两者之间的区别在于第二个是指定两个范围而不是一个 - 任何人都知道为什么突然停止工作?

with xlApp.Workbooks(1)
.Charts("Patients").SetSourceData Source:=.Sheets("Patient Numbers").Range("A" & TopRow - 1 & ":C" & CurRow - 1), PlotBy:=xlColumns
.Charts("Financial").SetSourceData Source:=.Sheets("Financial Monthly").Range("A" & TopRow - 1 & ":A" & CurRow - 1 & ",H" & TopRow - 1 & ":H" & CurRow - 1), PlotBy:=xlColumns
end with

1 个答案:

答案 0 :(得分:0)

Office 64位 - 我认为这可能是破坏它的原因。

使用Union修复它

with xlApp.Workbooks(1)
   .Charts("Patients").SetSourceData Source:=.Sheets("Patient Numbers").Range("A" & TopRow - 1 & ":C" & CurRow - 1), PlotBy:=xlColumns
   .Charts("Financial").SetSourceData Source:=Union(.Sheets("Financial Monthly").Range("A" & TopRow - 1 & ":A" & CurRow - 1 & "),.Sheets("Financial Monthly").RangeH" & TopRow - 1 & ":H" & CurRow - 1)), PlotBy:=xlColumns
end with