Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
File Excel VBA-尝试从Excel文件目录中提取数据,继续_File_Loops_While Loop - Fatal编程技术网

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

File Excel VBA-尝试从Excel文件目录中提取数据,继续,file,loops,while-loop,File,Loops,While Loop,可能重复: 所以我一直在努力把人们发给我的代码整合起来,这就是我到目前为止得到的 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(Fo

可能重复:

所以我一直在努力把人们发给我的代码整合起来,这就是我到目前为止得到的

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    
Dim xcell作为范围
Dim ycell As系列
将sheetname设置为字符串
Dim wbList()作为字符串,wbCount作为整数,i作为整数
将wbname设置为字符串
FolderName=“\\Drcs8570168\shasad\Test”
wbname=Dir(文件夹名和“\”和“*.xls”)
而wbname“”
设置ycell=范围(“a5”、“h5”)
设置xcell=范围(“a2”、“h2”)
sheetname=“登录表单”
ycell.Formula=“=”&“”&FolderName&“\[”&wbname&“]”_
&sheetname&“'!”和xcell.地址
温德
端接头

由于我对这种类型的代码不太熟悉,所以我对人们提供给我的代码没有太大的改变,但我希望它们在一起会有一些意义。问题似乎是循环不会停止,也不会输出任何东西。

我不打算提供代码,因为为了学习,您应该自己解决这个问题。(如果您正在寻找为您编写整个代码的人,那么您的站点是错误的-您需要尝试类似的地方。)

这应该让你开始,不过

wbList()
是一个字符串数组。它应该是分配
Dir()
的返回值的位置


对于
wbList
中的每个元素,将字符串分配给
wbName
。这就是为
wbCount
i
声明的内容-
wbCount
将是
wbList
中的字符串数,
i
将是迭代数组时的当前索引。

抱歉,出错了。它确实输出了3行(目录中只有3个文件),但它们都来自同一个文件,所以看起来它没有向下移动文件列表。。。