Ask Your Question
0

find and replace macro

asked 2017-09-06 16:23:12 +0200

fbertoldi gravatar image

How can I write a find and replace macro to merge many items in few, as "USA, Mexico, Canada, Honduras" in "America", "China, India, Vietnam" in "Asia" and so. Before macro: USA, Mexico, Canada, Honduras After macro: America, America, America, America

Thanks

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2017-09-06 16:59:45 +0200

JohnSUN gravatar image

updated 2017-09-06 17:00:13 +0200

It can be something like this:

Sub Geographer
Dim oDoc As Variant
Dim oSearchDescriptor As Variant
Dim oDictionary As Variant
Dim oReplace As Variant
Dim oStatusIndicator As Variant
Dim i As Long, j As Long 
    oDoc = ThisComponent
    oStatusIndicator = oDoc.getCurrentController().getStatusIndicator()
    oDictionary = Array( _
    Array("America",    "USA", "Mexico", "Canada", "Honduras"), _
    Array("Asia",       "China", "India", "Vietnam"), _
    Array("Europe",     "Ukraine", "Italy", "France", "Germany"), _
    Array("Africa",     "Qatar", "Tunisia") )
    oSearchDescriptor = oDoc.createSearchDescriptor()
    oStatusIndicator.start("", UBound(oDictionary)+1)
    For i = LBound(oDictionary) To UBound(oDictionary)
        oReplace = oDictionary(i)
        oSearchDescriptor.setReplaceString(oReplace(0))
        oStatusIndicator.setText(oDictionary(i)(0))
        oStatusIndicator.setValue(i+1)
        For j = 1 To UBound(oReplace)
            oSearchDescriptor.setSearchString(oReplace(j))
            oDoc.replaceAll(oSearchDescriptor)
        Next j
    Next i
    oStatusIndicator.end()
End Sub
edit flag offensive delete link more

Comments

Thank you very much. I will try.

fbertoldi gravatar imagefbertoldi ( 2017-09-07 10:46:42 +0200 )edit

It works perfectly!!! Very good. Thank you!!

fbertoldi gravatar imagefbertoldi ( 2017-09-07 10:49:42 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-09-06 16:23:12 +0200

Seen: 413 times

Last updated: Sep 06 '17