ExecuteExcel4Macro to get range/charts from closed workbooks

…衆ロ難τιáo~ 提交于 2019-12-09 00:18:37

问题


I use these lines to get values from closed workbooks:

Arg = "'" & Path & "[" & File & "]" & Sheet & "'!" & "R4C4"  
 Arg = CStr(Arg)
GetValue = 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.

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.

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.


回答1:


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


来源:https://stackoverflow.com/questions/16981081/executeexcel4macro-to-get-range-charts-from-closed-workbooks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!