开发者

Excel VBA - Trying to pull data from directory of excel files, continued [duplicate]

开发者 https://www.devze.com 2023-04-07 06:53 出处:网络
This 开发者_StackOverflow社区question already has answers here: Closed 11 years ago. Possible Duplicate:
This 开发者_StackOverflow社区question already has answers here: Closed 11 years ago.

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.


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 of Dir() is assigned.

For each element in wbList you assign the string to wbName. That's what wbCount and i are declared for - wbCount would be the number of strings in wbList, and i would be the current index as you iterate through the array.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号