In VBA, how do I convert An array from one type to another?, in my case i want to convert an array of type "String" to type "variant" because i have a function parameter that needs an array of that type.
here is an example code,
Sub test_highlighfind()
Dim Rng As Range: Set Rng = ThisDocument.Range.Paragraphs(6).Range
Dim arr() As String: arr = Split(Rng.Text)
Call highlightWordsUsingFind(arr, ThisDocument, 7)
End Sub
Sub highlightWordsUsingFind(ByRef arr() As Variant, ByRef doc As Document, _
Optional ByVal HighlightColor As Integer = 6)
Dim i As Long, SearchRange As Range
Set SearchRange = doc.Range
With SearchRange.Find
.Format = True
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Forward = True
.Wrap = wdFindContinue
.ClearFormatting
For i = LBound(arr) To UBound(arr)
.Text = arr(i)
.Execute 'Execute// Runs the find operation. Returns True if the find operation is successful
SearchRange.HighlightColorIndex = HighlightColor
Next
End With
End Sub
i know i can change the parameter type to "string" ByRef arr() As String
but i have other functions that return an array of type "variant" and i need the output to the function above