3

I'd like to know if there's a convenient way to sort a returned list alphabetically in VBA when the 'Dir' command is used. For example, if I find files using:

strPath = "C:\path\to\pics\"
strFileSpec = "*.png"

' -------------------------- '

strTemp = Dir(strPath & strFileSpec)

how can I iterate through them alphabetically?

Thanks in advance!

0

1 Answer 1

4

VBA doesn't have a built in array sort function. Fortunately, this problem has been solved already by others.

This code was written by Chip Pearson and can be found on his website. It implements the quick sort algorithm.

You can use it like this:

QSortInPlace(InputArray)
For i = lbound(InputArray) to ubound(InputArray)
    ' process array items
Next i
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.