Hello,
i got this code form here :https://stackoverflow.com/questions...ion-using-vba-macro-in-word/25102373#25102373
i am trying to make it write the second or third result stored in matchcollection, but i am stucked. When i use Msgbox i see all the resultates, but i can't write in excell cells
Public Function TestRegExp(myString As String, NrCrt As Long)
'Create objects.
Dim objRegExp As RegExp
Dim colMatches As MatchCollection, objMatch As Match
Dim RetStr As String, valori(0 To 100) As String
Dim i As Long, f As Long
Set objRegExp = New RegExp ' Create a regular expression object.
objRegExp.Pattern = "([a-z]{3}\d{5})\W" 'Set the pattern by using the Pattern property.
objRegExp.IgnoreCase = True 'Set Case Insensitivity.
objRegExp.Global = True 'Set global applicability.
If (objRegExp.Test(myString) = True) Then 'Test whether the String can be compared.
'Get the matches.
Set colMatches = objRegExp.Execute(myString) ' Execute search.
For Each objMatch In colMatches ' Iterate Matches collection.
i = 0
valori(i + 1) = objMatch.SubMatches(i)
' MsgBox objMatch.SubMatches(0)
i = i + 1
Next objMatch
Set objMatch = Nothing
Set colMatches = Nothing
Set objRegExp = Nothing
End If
TestRegExp= valori(NrCrt)
End Function
Thx for help
i got this code form here :https://stackoverflow.com/questions...ion-using-vba-macro-in-word/25102373#25102373
i am trying to make it write the second or third result stored in matchcollection, but i am stucked. When i use Msgbox i see all the resultates, but i can't write in excell cells
Public Function TestRegExp(myString As String, NrCrt As Long)
'Create objects.
Dim objRegExp As RegExp
Dim colMatches As MatchCollection, objMatch As Match
Dim RetStr As String, valori(0 To 100) As String
Dim i As Long, f As Long
Set objRegExp = New RegExp ' Create a regular expression object.
objRegExp.Pattern = "([a-z]{3}\d{5})\W" 'Set the pattern by using the Pattern property.
objRegExp.IgnoreCase = True 'Set Case Insensitivity.
objRegExp.Global = True 'Set global applicability.
If (objRegExp.Test(myString) = True) Then 'Test whether the String can be compared.
'Get the matches.
Set colMatches = objRegExp.Execute(myString) ' Execute search.
For Each objMatch In colMatches ' Iterate Matches collection.
i = 0
valori(i + 1) = objMatch.SubMatches(i)
' MsgBox objMatch.SubMatches(0)
i = i + 1
Next objMatch
Set objMatch = Nothing
Set colMatches = Nothing
Set objRegExp = Nothing
End If
TestRegExp= valori(NrCrt)
End Function
Thx for help