Word VBA - Find. To find Style 1 or Style 2 or Style 3

Word VBA - I'm using this code to Find text of Heading 1, 2 and 3 styles.

In a Do .... Loop

        With rngContent.Find
         .ClearFormatting
         .Style = "Heading 1"
         .Execute Forward:=True
        End With

Open in new window


As you can see it will only find ONE style. Is it possible to modify the Find to find "Heading 1" OR "Heading 2" OR "Heading 3"?

I know I can run it 3 times.  But I want the Headings to be found so that when I put them into an Array they are in the same order as they occur on the document. FYI the styles are an Outline in 3 levels.

Thanks
hindersalivaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
Hi,

You could fill a 2D array with what you've found and the position of its first character then sort it by the position

for an example of 2d sorting refer to
https://www.experts-exchange.com/questions/27345467/VBA-Sorting-array-based-on-priority-list.html

Regards
0
hindersalivaAuthor Commented:
Rgonzo, yes a sort would solve it - after looping 3 times. Would that be quick? The array is 5 x 1000 approx. of short string data.
0
Rgonzo1971Commented:
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Rgonzo1971Commented:
you could possibly use ADO to sort even more quickly
an example
Sub Macro()
Dim rstADO As Object
Dim fld As Object

Set rstADO = CreateObject("ADODB.Recordset")
With rstADO
    .Fields.Append "Position", adDouble, , adFldMayBeNull
    .Fields.Append "StyleText", adVarChar, -1, adFldMayBeNull

    .CursorType = adOpenKeyset
    .CursorLocation = adUseClient
    .LockType = adLockPessimistic
    .Open
End With

For Idx1 = 1 To 3
    For Idx2 = 1 To 5000
        rstADO.AddNew
        rstADO.Fields(0) = CDbl(Idx2 & "." & Idx1)
        rstADO.Fields(1) = Idx1 & "-" & Idx2
        rstADO.Update
    Next
Next
rstADO.MoveFirst
rstADO.Sort = "Position ASC"
arrRes = rstADO.getRows(Fields:="StyleText")
Set rstADO = Nothing
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hindersalivaAuthor Commented:
Wow Rgonzo! I never knew of rst.Sort
I didn't know ADO is that powerful.

That means, in cases like this, it is better to use an ADO recordset instead of an array. Am I right?
Or, to sort an array, transfer the data into a recordset, sort, and transfer back into the array?


I have a further idea. I shall post that as a separate question. TBA.
0
Rgonzo1971Commented:
I didn't test really  but in an interpreted language like VBA, doing a function oneself is (most of the time) slower (especially if the data needs a lot of work)
0
hindersalivaAuthor Commented:
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.