How do I get a single file name out of a File Dialog object in VBA (for MS Access 2007)?

前端 未结 3 2023
暖寄归人
暖寄归人 2021-01-02 21:22

How do I change my code to get the file name instead of the directory name? openDialog.InitialFilename gives me the directory name.
openDialog.FileNam

3条回答
  •  渐次进展
    2021-01-02 22:24

    I needed to select a single text file... this is what I did... it worked fine.

    ' Get the File
    '----------------------------------------------------------
    Dim dialog As Object
    Dim pickedfile As Boolean
    Dim myfile As String
    Set dialog = Application.FileDialog(msoFileDialogFilePicker)
    With dialog
        .AllowMultiSelect = False
        .Title = "Please pick the file to convert."
        .Filters.Clear
        .Filters.Add "Text Files", "*.TXT"
        .Filters.Add "All Files", "*.*"
        pickedfile = False
        pickedfile = .Show
        If pickedfile Then
        myfile = .SelectedItems.Item(1)
        End If
    End With
    '----------------------------------------------------------
    

    Additionally... you can replace the dialog type with...

    Set dialog = Application.FileDialog(msoFileDialogOpen)
    

    and it worked equally well.

提交回复
热议问题