macro to remove profanity and swear words in word files

Lynnita Seibel 20 Reputation points
2026-01-24T09:55:05.2066667+00:00

Hi there, I edit books with on aspect being removing swear words. I have never used a macro but there probably is a way to remove a set of words with **** or simply blanks. How can this be accomplished? Many thank, L.


Mod moved from : Microsoft 365 and Office | Word | For home | Windows

Developer technologies | Visual Basic for Applications
0 comments No comments
{count} votes

Answer accepted by question author
  1. Q&A Assist
    2026-01-24T09:55:17.05+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To create a macro in Microsoft Word that removes profanity or swear words, you can use VBA (Visual Basic for Applications). Below is a simple example of how you might set up such a macro. This macro will replace specified swear words with asterisks (****) or simply remove them.

    1. Open Microsoft Word.
    2. Press ALT + F11 to open the VBA editor.
    3. In the editor, click Insert > Module to create a new module.
    4. Copy and paste the following code into the module:
    Sub RemoveProfanity()
        Dim swearWords As Variant
        Dim i As Integer
        Dim rng As Range
    
        ' List of swear words to remove
        swearWords = Array("swearword1", "swearword2", "swearword3")
    
        ' Loop through each word in the list
        For i = LBound(swearWords) To UBound(swearWords)
            ' Set the range to the entire document
            Set rng = ActiveDocument.Content
            ' Replace the swear word with asterisks
            rng.Find.Execute FindText:=swearWords(i), ReplaceWith:="****", Replace:=wdReplaceAll
        Next i
    End Sub
    
    1. Replace "swearword1", "swearword2", "swearword3" with the actual words you want to filter out.
    2. Close the VBA editor and return to Word.
    3. To run the macro, press ALT + F8, select RemoveProfanity, and click Run.

    This macro will replace any instance of the specified swear words in the document with asterisks. If you want to remove the words entirely instead of replacing them with asterisks, change ReplaceWith:="****" to ReplaceWith:="".


    References:

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.