我有一堆 Excel 工作簿,它们存储在不同文件夹中的共享在线目录(有点像 Dropbox)中。我正在创建一个主工作簿,以将这些 Excel 工作簿中的值提取到摘要中。在测试时,如果工作簿存储在我的磁盘驱动器中并且我引用它们的目录,但不是通过它们存储的 HTTP 链接,我设法创建了一个可以工作的。
我目前正在使用ExecuteExcel4Macro
宏从计算机上已关闭的工作簿中检索值并将目录作为参数传递。例如,如果它是硬盘驱动器上的目录,则某些代码可以工作:
Private Function GetValue(path, file, sheet, ref)
' Retrieves a value from a closed workbook
Dim arg As String
' Make sure the file exists
If Right(path, 1) <> "\" Then path = path & "\"
If Dir(path & file) = "" Then
GetValue = "File Not Found"
Exit Function
End If
' Create the argument
arg = "'" & path & "[" & file & "]" & sheet & "'!" & _
Range(ref).Range("A1").Address(, , xlR1C1)
' Execute an XLM macro
GetValue = ExecuteExcel4Macro(arg)
End Function
Sub TestGetValue()
p = "c:\XLFiles\Budget"
f = "Budget.xls"
s = "Sheet1"
a = "A1"
MsgBox GetValue(p, f, s, a)
End Sub
有没有办法让它与 Excel 工作簿而不是目录的直接 HTTP 链接一起工作?将它们全部下载到我的计算机中并不是一个真正的选择,除非我可以以某种方式将其更改为自动下载每个工作簿,获取值然后删除它,或者类似的东西?