Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用VBA从关闭的excel工作簿获取信息_Excel_Vba - Fatal编程技术网

使用VBA从关闭的excel工作簿获取信息

使用VBA从关闭的excel工作簿获取信息,excel,vba,Excel,Vba,我试图使用excel VBA从关闭的工作簿中提取信息,更具体地说,是将关闭的excel工作簿中的一系列数字的总和提取到我当前的excel工作簿中 我尝试了以下代码: 我想找到从Z8到列中最后一个Z单元格的值之和 Range("D4").Formula = "Sum('I:\Outgoing\Money Outgoing\'!$Z8:$Z)" 我不想打开已关闭的工作簿 excel文件是Money outing.xlsx 文件中只有一个选项卡。选项卡名称为布局1,无需打开工作簿,即可使用以下代码。

我试图使用excel VBA从关闭的工作簿中提取信息,更具体地说,是将关闭的excel工作簿中的一系列数字的总和提取到我当前的excel工作簿中

我尝试了以下代码:
我想找到从Z8到列中最后一个Z单元格的值之和

Range("D4").Formula = "Sum('I:\Outgoing\Money Outgoing\'!$Z8:$Z)"
我不想打开已关闭的工作簿 excel文件是Money outing.xlsx
文件中只有一个选项卡。选项卡名称为布局1,无需打开工作簿,即可使用以下代码。 根据您的需要进行修改

Sub ExecuteMacroForClosedWorkbook()

Dim FldrName As String
Dim FlName As String
Dim WrkshtName As String
Dim ExecuteStringVariable As String

ExecuteStringVariable = "'" & FldrName & "\" & "[" & FlName & "]" & WrkshtName & "'!R"

ActiveCell.value = ExecuteExcel4Macro(ExecuteStringVariable & 1 & "C1") 'Execute A1 Cell and Transfer Value to Your ActiveCell

End Sub

我会避免像这样链接工作簿。
I:
是映射的网络驱动器吗?如果有人将其重命名为2019-2020.xlsx会怎么样?您可能可以尝试
Sheet1.Range(“D4”).Formula=“=Sum('[I:\outing\Money outing.xlsx]Layout 1'!$Z8:$Z10000)”
。我也看到了。祝你好运谢谢Mathieu,为了避免引用Z10000,但是要引用最后一个z单元格,它是$Z8:$z吗?不,如果不打开文件,就不能这样做<代码>$Z8:$Z对于Excel来说是一个语法错误。谢谢Mathieu!这帮了大忙。如果可能的话,如果你有时间的话,你可以看看我的其他帖子吗?谢谢mehmet,我还有一个问题。
Sub ExecuteMacroForClosedWorkbook()

Dim FldrName As String
Dim FlName As String
Dim WrkshtName As String
Dim ExecuteStringVariable As String

ExecuteStringVariable = "'" & FldrName & "\" & "[" & FlName & "]" & WrkshtName & "'!R"

ActiveCell.value = ExecuteExcel4Macro(ExecuteStringVariable & 1 & "C1") 'Execute A1 Cell and Transfer Value to Your ActiveCell

End Sub