Excel的VBA - 试图从Excel文件的目录中提取数据,继续

问题描述:

可能重复:
Excel - VBA Question. Need to access data from all excel files in a directory without opening the filesExcel的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  

因为我不熟悉这个代码类型我从人们提供给我的东西没有太大改变,但我希望它们能够在一起。问题似乎是循环不会停止,也不会输出任何东西。

+0

对不起,犯了一个错误。它确实输出3行(目录中只有3个文件),但它们都来自同一个文件,所以它看起来好像没有向下移动文件列表。 – user960358

我不打算提供代码,你应该为了学习工作了这一点自己。 (如果你正在找人来写整个代码给你,你在错误的站点 - 你需要尝试像Rentacoder某处)

这应该让你开始,虽然...

wbList()是一串字符串。它应该是指定返回值Dir()的位置。

对于每一个元素在wbList您指定的字符串wbName。这就是wbCounti被宣布为 - wbCount将是wbList串的数量,和你通过数组迭代i将是目前指数。