【发布时间】:2016-07-20 02:25:17
【问题描述】:
我有一个功能要求用户选择一个文件夹,然后选择另一个应该输出该文件夹中所有文件名的功能。 我一直在尝试以下但它不起作用,因为文件夹地址包含空格。你能帮忙吗?
'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\每日总结
【问题讨论】:
-
GetFolder函数的代码是什么?什么是“空格”? -
@MacroMan 请查看编辑后的帖子