vba FileDalog.Filters特定类型的文件名并按创建日期排序

时间:2015-06-19 02:01:25

标签: vba

问题:我想过滤掉那些包含%Card%.txt的文件名(例如xyz hij。 txt )我希望列出文件按创建日期降序排列以下是我尝试的代码。

Sub ImportData()

    Dim TargetFileDialog As Office.FileDialog
    Set TargetFileDialog = Application.FileDialog(msoFileDialogFilePicker)

    'Open File Dialog to get File Path
    With TargetFileDialog
        'User can only imporot one file at a time
        .AllowMultiSelect = False
        'Auto direct user to specific folder
        .InitialFileName = "desiredpath\"
        'Add filter
        .Filters.Clear
        .Filters.Add "All Files", "*.txt", 1
        If .Show = -1 Then
            For Each TargetFile In .SelectedItems
            ImportFile = TargetFile
            Next TargetFile
        End If
    End With

End Sub

0 个答案:

没有答案