【发布时间】:2011-09-03 17:54:03
【问题描述】:
我正在尝试使用 VBA Excel 2011 在 Mac OS X 上的文件夹中循环文件。我尝试了以下代码,但它不起作用。
Sub ListAllFilesInDir()
Dim strFile As String
Dim strPath1 As String
strPath1 = ActiveWorkbook.FullName
MsgBox strPath1
strFile = Dir(strPath1)
MsgBox strFile
strFile = Dir()
MsgBox strFile
strFile = Dir()
MsgBox strFile
End Sub
当程序到达第一个MsgBox strFile 时,我得到了活动工作簿的名称。我在某处读到使用不带参数的Dir 会导致文件夹中的下一个文件。但这对我不起作用。我收到第二个 MsgBox strFile 命令的空消息框和第三个 MsgBox strFile 命令的错误(运行时错误 5:无效的过程调用或参数)。我试图循环遍历的文件夹中有 4 个文件。
另外,我该怎么做才能只列出“.xslx”文件
【问题讨论】:
-
如果您还在寻找答案,请查看此链接:stackoverflow.com/questions/10045474/…