Chris H
Chris H

Reputation: 351

Find position in array of strings in Word VBA

I have an array of strings "alpha", "beta"... and I'd like to test another string string2 against this to return 1, if string2 = "alpha", 2 if it equals "beta" etc.

I could do this if it were Excel using application.match, but this doesn't exist in Word.

The end goal is to return the unicode value for the appropriate Greek letter from the name of the letter, so if there's a better way of doing it, I'm open to suggestions. Maybe I've been writing too much python, and lists seem like the easy way.

Upvotes: 0

Views: 1867

Answers (1)

Declan_K
Declan_K

Reputation: 6826

You need to loop through the array and test each value against the searched value.

Here's some pseudo code to get you started.

Dim greek() As String
Dim x As Integer
Dim searchString As String
Dim match As Integer

For x = LBound(greek) To UBound(greek)
    If greek(x) = searchString Then
        match = x
        Exit For
    End If
Next x

Upvotes: 1

Related Questions