ExecuteExcel4Macro从封闭的工作簿获取范围/图表 [英] ExecuteExcel4Macro to get range/charts from closed workbooks

查看:210
本文介绍了ExecuteExcel4Macro从封闭的工作簿获取范围/图表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I use these lines to get values from closed workbooks:

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

有没有其他的方法比循环来获取范围的值?循环解决方案正在工作,但是如果我可以直接使用ExecuteExcel4Macro获得范围将会更加清晰。我试图在Arg中输入一个范围,但它不起作用。它返回一个错误。

Is there an other way than loop to get values from a range ? The loop solution is working but It would be clearer if I can get range directly with ExecuteExcel4Macro. I've tried to input a range in Arg, but it doesn't work. It returns an error.

我对图表有同样的问题,我怎么能得到它们?我目前的解决方案是获取价值并重新绘制图表。它的工作原理,但我会对GetChart(Chartname)函数感到高兴。

I have the same question for charts, how can I get them ? My solution for the moment consist in getting values and replotting the charts. It works, but I would be happier with a GetChart(Chartname) function.

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

I've seen that I can use ADODB connection to get value from closed workbooks. But it was a little too complex compared to ExecuteExcel4Macro. Would it be easier to use ADODB connection in the case of range/charts.

推荐答案

以下代码段从范围在封闭的工作簿中,并在活动工作簿中以相同的范围复制:

The following bit of code pulls info from a range in a closed workbook and copies it in the same ranges in the Active Workbook:

    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

这篇关于ExecuteExcel4Macro从封闭的工作簿获取范围/图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆