我有以下 VBA 代码,用于在 MS ACCESS 表单中浏览文件名:
Private Sub Command64_Click()
Dim dialog As FileDialog
Dim filePath As String
Dim fileName As String
Set dialog = Application.FileDialog(msoFileDialogFilePicker)
With dialog
.AllowMultiSelect = False
.Show
If (.SelectedItems.Count = 0) Then
Else
filePath = .SelectedItems.Item(1)
fileName = Right$(filePath, Len(filePath) - InStrRev(filePath, "\"))
Me.Thumbnail = fileName
End If
End With
End Sub
我想为文件浏览器打开的位置设置一个默认位置。这可能吗?
最佳答案
您可以使用 FileDialog 方法的 InitialFileName 属性。
Private Sub Command64_Click()
Dim dialog As FileDialog
Dim filePath As String
Dim fileName As String
Set dialog = Application.FileDialog(msoFileDialogFilePicker)
With dialog
.AllowMultiSelect = False
.InitialFileName = "C:\yourFolderNameHere\"
.Show
If .SelectedItems.Count <> 0 Then
filePath = .SelectedItems.Item(1)
fileName = Right$(filePath, Len(filePath) - InStrRev(filePath, "\"))
Me.Thumbnail = fileName
End If
End With
End Sub
关于ms-access - 设置默认文件浏览位置 VBA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25017131/