|
在新的office版本中(officeXP及以上,我想),可以引用microsoft office 11.0(10.0) object library来做这些事情。Private Sub btnFileDlg_Click()
'这里演示的是如何用microsoft office 11.0 object library
'里的fileDialog对象打开文件选择对话框
Dim fileDlg As Office.FileDialog
Dim varFile As Variant
Set fileDlg = Application.FileDialog(msoFileDialogFilePicker)
With fileDlg
.AllowMultiSelect = False '只允许选择一个文件
.Title = "选择一个文件"
.Filters.Clear
.InitialFileName = CurrentProject.Path
.Filters.Add "mdb文件", "*.mdb",1
.Filters.Add "adp文件", "*.adp",1
.Filters.Add "所有文件", "*.*"
If .Show = True Then
For Each varFile In .SelectedItems
Me.txtFilePath = varFile
Next
End If
End With
Set fileDlg = Nothing
End Sub
|
|