我有一个功能,要求用户选择一个文件夹,然后另一个应该输出该文件夹中的所有文件名。 我一直在尝试以下但它不起作用,因为文件夹地址包含空格。你能帮忙吗?
'gets folder address
recsFolder = Functions.GetFolder("C:\")
'Loop through files in folder
Dim StrFile As String
StrFile = Dir(recsFolder)
Do While Len(StrFile) > 0
Debug.Print StrFile
StrFile = Dir
Loop
谢谢!
编辑: GetFolder代码
Function GetFolder(strPath As String) As String
Dim fldr As FileDialog
Dim sItem As String
Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
With fldr
.Title = "Select a Folder"
.AllowMultiSelect = False
.InitialFileName = strPath
If .Show <> -1 Then GoTo NextCode
sItem = .SelectedItems(1)
End With
NextCode:
GetFolder = sItem
Set fldr = Nothing
End Function
空格我指的是地址中存在的空格(即每日和摘要之间) C:\ Users \ User1 \ Desktop \ Daily Summary
答案 0 :(得分:1)
您需要为Dir()
提供文件模式才能列出文件。
更改为:
StrFile = Dir$(recsFolder & "\*.*")
答案 1 :(得分:0)
更改
StrFile = Dir(recsFolder)
要
StrFile = Dir(recsFolder & "\*.*")