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

标签 ms-access vba

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

相关文章:

与 MS Access 的 java 连接

sql - 在 Access 查询中使用表单中的日期字段

vba - 如何将一列中的数据拆分为两个单独的列?

vba - 如何从Application.Path获取UNC路径?

vba - OpenArgs 是 Null 问题

sql - 根据字段值增量并创建记录

ms-access - 以编程方式添加到 MS Access 关系图

ms-access - MS Access - 右键单击​​对象已禁用

VBA PowerPoint 文本框文本对齐

vba - Excel vba 中的 "No Cells Found Error"