A Microsoft Word Office Add-in that automatically highlights all occurrences of the word "hello" (or any custom word) in your document using Office.js API.
- Automatic Search: Searches for all occurrences of a specified word in the document
- Yellow Highlighting: Highlights found words with a bright yellow background
- Placeholder Conversion: Convert highlighted words to placeholder format (e.g., "hello" → "{{hello}}")
- Customizable: Change the search word and toggle case sensitivity
- Clear Function: Remove all highlights with one click
- Status Updates: Real-time feedback on search results
- Task Pane Interface: Clean, user-friendly interface
hello-highlighter-addin/
├── manifest.xml # Add-in manifest file
├── taskpane.html # Main UI for the task pane
├── taskpane.js # JavaScript logic for highlighting
├── commands.html # Commands page (required by manifest)
├── server.js # Express server for local development
├── package.json # Node.js dependencies
├── assets/ # Directory for icon files
└── README.md # This file
npm installnpm startThe server will start with HTTPS support and display:
Generated self-signed HTTPS certificates for localhost
Hello Highlighter Add-in server running on https://localhost:3000
Manifest available at: https://localhost:3000/manifest.xml
Task pane available at: https://localhost:3000/taskpane.html
HTTPS enabled - compatible with Word Online!
Accept HTTPS Certificate:
- Open Edge browser and navigate to
https://localhost:3000 - Click "Advanced" → "Continue to localhost (unsafe)" when you see the security warning
- Verify you see the server page
Upload Add-in:
- Open Word Online in Edge (
office.com→ Word) - Create a new document
- Go to Insert → Add-ins → More Add-ins
- Click "Upload My Add-in" or "Advanced Options"
- Select the
manifest.xmlfile and upload
Use the Add-in:
- Find "Hello Highlighter" in the Home tab ribbon
- Click "Show Taskpane" to open the interface
- The add-in will automatically highlight all instances of "hello"
- Open Microsoft Word (desktop version)
- Create a new document
- Go to Insert → Office Add-ins
- Click "Upload My Add-in"
- Select the
manifest.xmlfile and upload
- Click "Show Taskpane" in the Home tab
- The add-in automatically searches for "hello" and highlights all occurrences
- Highlight Words: Search and highlight occurrences of your chosen word
- Convert to Placeholders: Transform highlighted words into placeholder format (e.g., "hello" becomes "{{hello}}")
- Clear Highlights: Remove all highlighting from the document
- Customize your search by changing the word or toggling case sensitivity
The add-in uses the Word JavaScript API to search documents using body.search(), apply yellow highlighting with font.highlightColor, track ranges for clearing, and provide user feedback.
Key code:
const searchResults = body.search(searchWord, {
matchCase: caseSensitive,
matchWholeWord: false,
matchWildcards: false
});
for (let i = 0; i < searchResults.items.length; i++) {
const range = searchResults.items[i];
range.font.highlightColor = '#FFFF00'; // Yellow
}-
Clone and setup:
git clone [your-repo-url] cd add-in npm install npm start -
Accept certificate: Go to
https://localhost:3000in Edge, click "Advanced" → "Continue to localhost" -
Test in Word Online: Open Word Online → Insert → Add-ins → Upload
manifest.xml -
See it work: Type "hello world" in the document, the add-in will highlight "hello" automatically!
Problem: SSL/Certificate errors in Word Online
Failed to load resource: net::ERR_SSL_PROTOCOL_ERROR
Failed to load resource: net::ERR_CERT_AUTHORITY_INVALID
Solution:
- Ensure HTTPS server is running (look for "HTTPS enabled" in console)
- Accept the certificate: Open
https://localhost:3000, click "Advanced" → "Continue to localhost" - Reload Word Online and try the add-in again
Problem: Server falls back to HTTP
HTTPS setup failed, falling back to HTTP
Hello Highlighter Add-in server running on http://localhost:3000
Solution:
npm install --save-dev selfsigned
npm startSolutions:
- Check server is running: Visit
https://localhost:3000/taskpane.htmldirectly - Clear browser cache: Ctrl+Shift+R in Word Online
- Re-upload manifest: Remove and re-add the add-in
- Check manifest URLs point to
https://localhost:3000
Word Online: Go to Insert → Add-ins → More Add-ins → "Upload My Add-in" or "Advanced Options" Desktop Word: Insert → Office Add-ins → Upload My Add-in
- Restart Edge completely
- Clear certificates: Edge Settings → Privacy → Clear browsing data → Cookies
- Re-accept certificate: Visit
https://localhost:3000again - Alternative: Use Firefox or Chrome for testing
Debug in Word Online:
- Press F12 in Word Online
- Console tab: Look for JavaScript errors
- Network tab: Check for failed requests to localhost:3000
- Right-click in task pane: Select "Inspect Element"
Normal console messages (ignore):
[Violation] Potential permissions policy violation: autoplay is not allowed
Some icons were re-registered
Error messages to watch for:
- Bad:
Failed to load resource: net::ERR_CERT_AUTHORITY_INVALID - Good:
Office.js is readyand200 GET https://localhost:3000/taskpane.html
Test server: curl -k https://localhost:3000 (should return HTML)
Test files:
- Manifest:
https://localhost:3000/manifest.xml - Task Pane:
https://localhost:3000/taskpane.html - JavaScript:
https://localhost:3000/taskpane.js
Test environments: Word Online, Desktop Word, different browsers
Main functions: highlightWords(), convertToPlaceholders(), clearHighlights(), searchAndHighlight(), getDocumentStats()
Office.js APIs: Word.run(), context.document.body, body.search(), range.font.highlightColor, context.sync()