我在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
答案 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