‘浏览文件和文件夹清单
Application.FileDialog(msoFileDialogFilePicker).Show
‘浏览文件夹清单
Application.FileDialog(msoFileDialogFolderPicker).Show
FileDialog 打开文件夹或文件
Dir 判断文件存在
Sub 按钮1_Click()
'选择单一文件夹
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show = -1 Then
'FileDialog 对象的 Show 方法显示对话框,并且返回 -1(如果您按 OK)和 0(如果您按 Cancel)。
MsgBox "您选择的文件夹是:" & .SelectedItems(1), vbOKOnly + vbInformation, "智能Excel"
Dim fileOfIndexHtml As String
fileOfIndexHtml = .SelectedItems(1) + "\index.html"
'如果文件不存在就返回空字符串
If Dir(fileOfIndexHtml) = "" Then MsgBox "文件夹中不存在,请重新指定文件目录!" Else MsgBox "该文件存在." + fileOfIndexHtml
End If
End With
End Sub
————————————————
版权声明:本文为CSDN博主「iteye_11020」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/iteye_11020/article/details/82412624
msoFileDialogFilePicker 允许用户选择文件。 |
---|
msoFileDialogFolderPicker 允许用户选择一个文件夹。 |
msoFileDialogOpen 允许用户打开文件。 |
msoFileDialogSaveAs 允许用户保存一个文件。 |