PDA

View Full Version : Solved: Sorting an Array



khagerman
03-06-2005, 01:09 PM
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?

mdmackillop
03-06-2005, 01:17 PM
Have a look at this item
http://www.vbaexpress.com/kb/getarticle.php?kb_id=103

khagerman
03-06-2005, 02:00 PM
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:


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


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!!