Consulting

Results 1 to 3 of 3

Thread: Solved: Sorting an Array

  1. #1

    Solved: Sorting an Array

    Using Word, I have vba that creates an array, populates with some file names and eventually pastes some pictures into the Word document using the file names of the pictures.

    I would like to sort the array, in vba, so the pictures will be loaded in order. Is there built-in method I can call to sort the array?

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location

  3. #3
    Thanks very much. I was going to put together a sort of it isn't available as a method and your bubble sort is very efficient!

    OK, I'm getting a compile error when I try to run:

    [VBA]
    Sub test()
    Dim strFileArray() As String
    While MyFileName <> ""
    ReDim Preserve strFileArray(i)
    strFileArray(i) = MyPath & MyFileName
    i = i + 1
    MyFileName = Dir()
    Wend
    BubbleSort (strFileArray)
    End Sub
    [/VBA]

    It stops on BubbleSort with the following error:

    Compile error:
    Type mismatch: array or user-defined type expected

    As you can see this is a dynamic array but I don't see how that could be a problem?

    Help!!

Posting Permissions

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