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

发布于 2024-12-06 05:43:25 字数 922 浏览 0 评论 0原文

可能的重复:
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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ら栖息 2024-12-13 05:43:25

我不会提供代码,因为您应该自己解决这个问题才能学习。 (如果您正在寻找某人为您编写整个代码,那么您在错误的站点 - 您需要尝试像 Rentacoder。)

不过,这应该可以帮助您开始...

wbList() 是一个字符串数组。它应该是 Dir() 的返回值被赋值的地方。

对于 wbList 中的每个元素,您将字符串分配给 wbName。这就是 wbCounti 的声明目的 - wbCountwbList 中的字符串数量,而 >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 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文