Using MS Word or Notepad++, I wish to find and replace a single vocabulary to multiple different synonyms.

For example, from my text, I found that a specific word AAAA appears too frequently. So, I wish to change this AAAA to BBBB, CCCC, or DDDD. Like find and replace "beautiful" to "astonishing", "pretty", or "alluring".

It can be random fashion (60% of BBBB, 30% of CCCC and 10% of DDDD, randomly) or it can be in order (replace to BBBB, then replace next one to CCCC, then replace next one to DDDD, then replace next one to BBBB again...)

Is it possible to perform such find and replace from MS Word or Notepad++? Would it be better to write a script or macro to perform such action?


Try this ... it should give you a start.

Sub FindReplaceSynonyms()
    Dim doc As word.Document, rng As word.Range
    Dim FindStr As String, SynonymStr As String
    Dim SplitStr() As String, i As Long
    Set doc = ActiveDocument
    Set rng = doc.Content
    FindStr = "beautiful"
    SynonymStr = "astonishing,pretty,alluring"
    SplitStr = Split(SynonymStr, ",")
    With rng.Find
        .Format = False
        .Forward = True
        .MatchCase = True
        .Text = FindStr
        .Wrap = wdFindStop
        Do While .found
            rng.Text = SplitStr(i)
            i = i + 1
            If i > UBound(SplitStr) Then i = 0
            rng.Collapse wdCollapseEnd
    End With
    MsgBox "Action Complete", vbExclamation, "Custom Replace"
End Sub
  • Thank you so much, I tested and this works perfect!! – exsonic01 Nov 13 '18 at 21:58

Notepad++ doesn't have random replace or even round-robin replace, and neither does regex. It is not a programming tool, and neither is Word.

Writing a script/macro is much better. If you are mentioning Word, then VBA can certainly do that. You may quick-start by recording a session where you do such replaces, then extend it with a loop.

Microsoft's article is a good starting point: Automate tasks with the Macro Recorder.

  • Thank you for your recommendation, I'm already reading. – exsonic01 Nov 13 '18 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.