Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting arrays 1

Status
Not open for further replies.

Stretchwickster

Programmer
Apr 30, 2001
1,746
GB
Hey folks!

Are there any methods within vba to sort arrays?

Your help would be much appreciated! Clive [infinity]
Ex nihilo, nihil fit (Out of nothing, nothing comes)
 
Doesn't matter. Create a Word object, wordbasic is child of that.

Other option is to do a UDF to sort an array - myself I prefer to do it the easy way.
 
Code:
Private Sub CommandButton1_Click()
Dim appWD As Word.Application, sort_arr(3) As String, i As Integer
Set appWD = CreateObject("Word.Application")
sort_arr(0) = "Z"
sort_arr(1) = "X"
sort_arr(2) = "8"
sort_arr(3) = "1"
Debug.Print "Before Sorting"
For i = 0 To 3
    Debug.Print sort_arr(i)
    Next
WordBasic.SortArray sort_arr
Debug.Print "After Sorting"
For i = 0 To 3
    Debug.Print sort_arr(i)
    Next
appWD.Quit
End Sub

The one weakness is that if you declare the array you want to sort as a variant, it won't work. Also remember to add a reference to the Word object library by selecting Tools > References then searching for word in the list box.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top