我有其他工作簿的工作簿中列出向下G列vba从列中列出的多个工作簿中获取值?
Folder\File1.xls
Folder\File2.xls
Folder\File3.xls
Folder\File4.xls
下面的VBA代码从小区C15的电子邮件地址,在所有这些工作簿,并将它们添加到列u像这样:
Folder\File1.xls Email
Folder\File2.xls Email
Folder\File3.xls Email
Folder\File4.xls Email
这是我的代码。
'//Email copy code
Dim startCell As Range, fileRng As Range
Dim files As Variant, values() As Variant, values2() As Variant
Dim path As String, file As String, arg As String
Dim r As Long, i As Long
'Acquire the names of your files
With ThisWorkbook.Worksheets(1) 'amend to your sheet name
Set startCell = .Range("G17") 'amend to start cell of file names
Set fileRng = .Range(startCell, .Cells(.Rows.Count, startCell.Column).End(xlUp))
End With
files = fileRng.Value2
'Size your output array
ReDim values(1 To UBound(files, 1), 1 To 1)
'Populate output array with values from workbooks
For r = 1 To UBound(files, 1)
'Create argument to read workbook value
i = InStrRev(files(r, 1), "\")
path = Left(files(r, 1), i)
file = Right(files(r, 1), Len(files(r, 1)) - i)
arg = "'" & path & "[" & file & "]Sheet1'!R15C3"
'Acquire the value
values(r, 1) = ExecuteExcel4Macro(arg)
Next
'Write values to sheet
fileRng.Offset(, 20).Value = values
此代码适用于我家里的windows笔记本电脑。但是,在工作中,我的IT部门禁用CMD和其他shell函数 - 我相信这些代码用于从工作簿中获取值。
因此,此代码不会从列C15中获取值。
任何人都可以给我一个解决方法吗?由于
好吧,有一件事代码看起来很像我昨天给你的代码(http://stackoverflow.com/questions/41637137/vba-get-email-address-from-each-workbook-in-a - 范围/ 41657368#41657368) - 你至少应该引用你的来源;另外,在两天内只有两个被接受的答案的7个问题是一个非常糟糕的节目,而不是这个网站的工作方式。也许你应该对所有你问他人的工作表现出一些恩惠。 – Ambie