Google Docs document and bolds specific words

Here’s a Google Apps Script that scans a Google Docs document and bolds specific words (Objective, Code, and Explanation) when they appear on their own lines.


Features:

  • Searches for the words Objective, Code, and Explanation when they are on their own lines.
  • Applies bold formatting to these words.
  • Works for any Google Docs document.

Google Apps Script:

function boldSpecificWords() {
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
var paragraphs = body.getParagraphs();

var wordsToBold = ["Objective", "Code", "Explanation"];

paragraphs.forEach(paragraph => {
var text = paragraph.getText().trim();

if (wordsToBold.includes(text)) {
paragraph.setBold(true);
}
});

Logger.log("Specified words have been bolded.");
}

How to Use:

  1. Open a Google Docs document.
  2. Click Extensions > Apps Script.
  3. Paste the script into the editor.
  4. Click Run.
  5. Authorize the script when prompted.
  6. The words Objective, Code, and Explanation will be bolded if they are on their own lines.