gpt4 book ai didi

excel - 执行Excel4Macro从关闭的工作簿中获取范围/图表

转载 作者:行者123 更新时间:2023-12-03 01:06:46 29 4
gpt4 key购买 nike

我使用这些行从关闭的工作簿中获取值:

Arg = "'" & Path & "[" & File & "]" & Sheet & "'!" & "R4C4"  
Arg = CStr(Arg)
GetValue = ExecuteExcel4Macro(Arg)

除了循环之外,还有其他方法从范围中获取值吗?循环解决方案正在工作,但如果我可以直接使用 ExecuteExcel4Macro 获取范围,情况会更清楚。我尝试在 Arg 中输入范围,但它返回错误。

我对图表有同样的问题,我怎样才能得到它们?目前我的解决方案包括获取值和重新绘制图表。它可以工作,但我会更喜欢 GetChart(Chartname) 函数。

我已经看到可以使用 ADODB 连接从关闭的工作簿中获取值。但与 ExecuteExcel4Macro 相比,它有点太复杂了。在范围/图表的情况下使用 ADODB 连接会更容易吗?

最佳答案

以下代码从关闭的工作簿中的某个范围中提取信息,并将其复制到事件工作簿中的相同范围中:

    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

关于excel - 执行Excel4Macro从关闭的工作簿中获取范围/图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16981081/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com