Results 1 to 3 of 3

Thread: [RESOLVED] [Office 2003] FileDialog Sorting

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Location
    Best Place on Earth
    Posts
    363

    Resolved [RESOLVED] [Office 2003] FileDialog Sorting

    I am using the code modified from the below to let the user select a file to process.

    However in some of these places they need to see the FileDiaglow sorted by Date/Time,
    whilst in others they need to see it sorted by Name.

    Is there any way to do this in VBA?

    Code:
    Dim fd As FileDialog
    
       'Create a FileDialog object as a File Picker dialog box.
        Set fd = Application.FileDialog(msoFileDialogFilePicker)
    
        'Use a With...End With block to reference the FileDialog object.
        With fd
            .AllowMultiSelect = False
            .Title = "Select File for Processing"
            .InitialFileName = ThisWorkbook.Path & "\*.xls"
            .InitialView = msoFileDialogViewDetails
            
            'Use the Show method to display the File Picker dialog box and return 
            ' the user's action.
            If .Show = -1 Then  'The user pressed the action button.
                debug.print .SelectedItems(1)
            Else ' The user pressed Cancel.
                MsgBox "Loading of File aborted"
            End If
        End With
    
        'Set the object variable to Nothing.
        Set fd = Nothing
    Signature Under Construction

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: [Office 2003] FileDialog Sorting

    i have seen /had code to do this for a common dialog, but not sure if it would work with an excel filedialog
    http://www.codeguru.com/forum/showthread.php?t=404040
    but, having looked at it again, i am not sure that this will work in vba owing to lack of hwnd
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Location
    Best Place on Earth
    Posts
    363

    Re: [Office 2003] FileDialog Sorting

    Thanks westconn.

    Looks like it cannot be done, except with a custom built dialog.
    Signature Under Construction

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width