我使用以下行从已关闭的工作簿中获取值:
Arg = "'" & Path & "[" & File & "]" & Sheet & "'!" & "R4C4"
Arg = CStr(Arg)
GetValue = ExecuteExcel4Macro(Arg)
除了循环之外,还有其他方法可以从范围中获取值吗?循环解决方案是有效的,但如果我能用ExecuteExcel4Macro
直接得到范围,那就更清楚了。我尝试在Arg
中输入一个范围,但它返回一个错误。
我对图表也有同样的问题,我怎样才能得到它们呢?我目前的解决方案是获取值并重新绘制图表。它可以工作,但我更喜欢使用GetChart(Chartname)
函数。
我已经看到,我可以使用ADODB连接从已关闭的工作簿中获取价值。但与ExecuteExcel4Macro
相比,它有点太复杂了。在range/charts的情况下使用ADODB连接会更容易吗?
发布于 2013-06-07 10:10:41
以下代码从已关闭工作簿的某个范围中提取信息,并将其复制到活动工作簿中的相同范围中:
Sub GetRange()
With Range("A1:D50") 'set range to copy from / to.
.Formula = "='C:\E3_Test\[CC_Data.xlsx]AllData'!A1" 'refers to a workbook, sheet and first cell.
'It will put the relative references into the target sheet correctly.
.Value = .Value 'changes formula to value.
End With
End Sub
https://stackoverflow.com/questions/16981081
复制