Results 1 to 3 of 3
  1. #1
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Sorting FileDialog (VBA/Word/2003)

    <P ID="edit" class=small>(Edited by wdwells on 16-Oct-07 12:10. Added " using VBA" to final paragraph.)</P> I am using the following code to allow the user to select or create and select a given folder.
    <pre>Public Sub Main(strFolder As String, CommPhrase As String, strPath As String, StartTime As Date, Abort As Boolean)

    Dim myTitle As String
    Dim Locn As Long
    Dim msg As String
    Dim Resp As Byte
    Dim UNC As String
    Dim FD

    10 myTitle = "Select " & CommPhrase
    Restart:
    15 Set FD = Application.FileDialog(msoFileDialogFolderPicker)
    'Identify the path for an existing folder
    20 With FD

    30 .Title = myTitle
    33 If strPath > "" Then
    35 .InitialFileName = strPath & ""
    37 End If
    40 If .Show = True Then
    50 strFolder = .SelectedItems(1)
    60 Else
    70 Abort = True
    80 Exit Sub
    90 End If
    100 End With
    115 Set FD = Nothing
    110 If Left(strFolder, 2) = "" Then
    120 strFolder = strFolder
    130 Else
    140 Call NetworkDrive.Main(strFolder, UNC, strFolder)
    150 End If
    </pre>


    After initial success, I now find that the dialog box is displaying the folders sorted in a user hostile manner. Searching through the Microsoft Knowledge Base, I am advised here
    <hr>Each host Office application can only instantiate a single instance of a FileDialog object. Many of the properties of the FileDialog object persist even when you create multiple FileDialog objects. Therefore, you should initialize all of the dialog properties appropriately for your purpose before you display the dialog box.<hr>
    I have been unable to find a technique using VBA to initialize the dialog properties such that the folders are sorted by name. Can someone provide any guidance?

    T.I.A.
    Regards
    Don

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Sorting FileDialog (VBA/Word/2003)

    The FileDialog object does not provide any method for sorting the files or folders it displays. The MSKB article applies to properties that can be set, such as file filters and whether multiple files can be selected.

    However, the user can change the sort order in the dialog from the right-click menu.

  3. #3
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Sorting FileDialog (VBA/Word/2003)

    Thank you Hans
    As always you have cleared away the fog. <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    Regards
    Don

Posting Permissions

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