首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为32位和64位MS-Access-2016选择要保存新文件的文件夹和文件名

为32位和64位MS-Access-2016选择要保存新文件的文件夹和文件名
EN

Stack Overflow用户
提问于 2021-05-01 16:02:45
回答 1查看 153关注 0票数 0

我正在尝试使用MS Access VBA中的文件对话框来获取完整的路径和文件名。在我的MS-Access项目中,我希望能够将数据保存到用户可选择的文件夹和文件名中。为了选择文件夹和文件名,MS-Access提供了FileDialog()函数。

--> FileDialog()

设置fDialog = Application.FileDialog(msoFileDialogSaveAs)

但是最新版本的MS-Access (特别是64位版本)的FileDialog函数不再支持msoFileDialogSaveAs选项。

有没有办法使用像最新版本的MS-Access的FileDialog对象这样的API函数从用户那里获取文件夹和文件名?

EN

回答 1

Stack Overflow用户

发布于 2021-05-01 17:38:47

有支持,但您需要Microsoft Office 16.0对象库的引用

枚举:

示例:

代码语言:javascript
复制
Public Function FileSaveDialog( _
    ByVal Filter As String, _
    ByVal Extension As String) _
    As String

    Dim FilterIndex As Long
    Dim FileName    As String
    
    With Application.FileDialog(msoFileDialogSaveAs)  ' 2
        For FilterIndex = 1 To .Filters.Count
            If (InStr(LCase(.Filters(FilterIndex).Description), LCase(Filter)) > 0) And _
                (LCase(.Filters(FilterIndex).Extensions) = LCase(Extension)) Then
                .FilterIndex = FilterIndex
                Exit For
            End If
        Next

        If .Show Then
            FileName = .SelectedItems(.SelectedItems.Count)
        End If
    End With
    
    FileSaveDialog = FileName

End Function
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67344119

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档