2011-09-23 56 views
-1

可能重複:
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

回答

1

我不打算提供代碼,你應該爲了學習工作了這一點自己。 (如果你正在找人來寫整個代碼給你,你在錯誤的站點 - 你需要嘗試像Rentacoder某處)

這應該讓你開始,雖然...

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

對於每一個元素在wbList您指定的字符串wbName。這就是wbCounti被宣佈爲 - wbCount將是wbList串的數量,和你通過數組迭代i將是目前指數。

相關問題