gpt4 book ai didi

ms-access - 设置默认文件浏览位置 VBA

转载 作者:行者123 更新时间:2023-12-05 04:17:01 34 4
gpt4 key购买 nike

我有以下 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/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com