1、写一个自定义函数
Function GetF(w As Boolean) As String
'功能说明:打开文件夹,返回文件名或返回文件夹名。
'参数:w=true 查找文件;w=false 查找文件夹
'引用:Microsoft Office 12.0 Object Library
Dim dlgOpen As FileDialog
If w = True Then
Set dlgOpen = Application.FileDialog(msoFileDialogFilePicker)
Else
Set dlgOpen = Application.FileDialog(msoFileDialogFolderPicker)
End If
With dlgOpen
.AllowMultiSelect = True
.Show
End With
If dlgOpen.SelectedItems.Count > 0 Then
GetF = dlgOpen.SelectedItems(1)
Else
GetF = ""
End If
Set dlgOpen = Nothing
End Function
2、在按钮单击事件中写:
me.路径.value=GetF(false)
3、其实这些都是多余的,参见以下示例就知道怎么简洁处理了:
http://www.accessoft.com/blog/article-show.asp?userid=10802&Id=9088