Excel VBA - 尝试从 Excel 文件目录中提取数据,继续
所以我一直在尝试将人们发送给我的代码放在一起,这就是我到目前为止所得到的......
Dim xcell As Range
Dim ycell As Range
Dim sheetname As String
Dim wbList() As String, wbCount As Integer, i As Integer
Dim wbname As String
FolderName = "\\Drcs8570168\shasad\Test"
wbname = Dir(FolderName & "\" & "*.xls")
While wbname <> ""
Set ycell = Range("a5", "h5")
Set xcell = Range("a2", "h2")
sheetname = "loging form"
ycell.Formula = "=" & "'" & FolderName & "\[" & wbname & "]" _
& sheetname & "'!" & xcell.Address
Wend
End Sub
自从我我对这种类型的代码不太熟悉,我没有对人们提供给我的代码进行太多更改,但我希望它在一起有意义。问题似乎是循环不会停止,也不会输出任何内容。
Possible Duplicate:
Excel - VBA Question. Need to access data from all excel files in a directory without opening the files
So I've been trying to put together the code people have been sending me and this is what I've got so far...
Dim xcell As Range
Dim ycell As Range
Dim sheetname As String
Dim wbList() As String, wbCount As Integer, i As Integer
Dim wbname As String
FolderName = "\\Drcs8570168\shasad\Test"
wbname = Dir(FolderName & "\" & "*.xls")
While wbname <> ""
Set ycell = Range("a5", "h5")
Set xcell = Range("a2", "h2")
sheetname = "loging form"
ycell.Formula = "=" & "'" & FolderName & "\[" & wbname & "]" _
& sheetname & "'!" & xcell.Address
Wend
End Sub
Since I'm not that familiar with this type of code I didn't change much from what people supplied me but I'm hoping it makes some sense together. The problem seems to be that the loop won't stop and it isn't outputting anything either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不会提供代码,因为您应该自己解决这个问题才能学习。 (如果您正在寻找某人为您编写整个代码,那么您在错误的站点 - 您需要尝试像 Rentacoder。)
不过,这应该可以帮助您开始...
wbList()
是一个字符串数组。它应该是Dir()
的返回值被赋值的地方。对于
wbList
中的每个元素,您将字符串分配给wbName
。这就是wbCount
和i
的声明目的 -wbCount
是wbList
中的字符串数量,而>i
将是您迭代数组时的当前索引。I'm not going to provide code, as you should work this out yourself in order to learn. (If you're looking for someone to write the entire code for you, you're at the wrong site - you need to try somewhere like Rentacoder.)
This should get you started, though...
wbList()
is an array of strings. It should be where the return value ofDir()
is assigned.For each element in
wbList
you assign the string towbName
. That's whatwbCount
andi
are declared for -wbCount
would be the number of strings inwbList
, andi
would be the current index as you iterate through the array.