Click on the link at the bottom of the page to return to Lazy Dogg’s Laziness Page.

A macro for Microsoft Word to change special characters into HTML codes.

Download the script.

BEFORE YOU START, this time-saver is mainly for web coders who like to work in text editors. If you’re doing OK with Front Page or Dreamweaver, it might not be much use to you.

Many web designers are sent Word documents and asked to put them onto a web page. “Easy!” you might say - “Just cut and paste the text into your text editor.” But you might run into problems, particularly if you’re following W3C guidelines and using UTF8 encoding: You’ll probably find some browsers aren’t showing the nice curly quotes or apostrophes. Some will show question marks, and others will show nothing at all, and you’ll get your client asking why you’ve left out all the apostrophes!

It gets worse when you’re dealing with other languages - I once had a load of Portuguese text, and had to go through putting in codes like “é” and “ü” all over the place.

SO, I thought I’d write a macro for Word that would do it all for me. This macro (which is probably very unwieldy - feel free to write something better if you’re good at that kind of thing) replaces all the characters (or most of them) which browsers won’t show properly. It’s a text document, so you’ll need to create a new macro in Word and paste it into the content, save it, then run on the document you want to convert.

“But Word saves to HTML anyway!” you may say. And it does. But it also saves a ton of styling information. For my purposes, I need to strip out all the formatting and apply my own CSS stylesheets. If you’re happy with Word’s styling, then you’re better off using Word’s HTML save than this. With OpenOffice, I’ve had more success with saving as HTML - it puts in a bit of styling information in the <p> tags, but a search‘n’replace clears any extra stuff pretty quickly.

How to use it

  1. First, you’ll need to download the script (right-click or control-click (for Mac users) the link and choose "Save target as" (or similar).
  2. Create a new macro in Word and paste the contents of the htmliser.txt document over it (I’ve only tested it on the Mac version of Office X but it should work on other versions I think).
  3. Save it and run it on your document.
  4. I’ve left out the HTML paragraph breaks (<p> and </p>) If you want to add them easily, use Word’s search and replace to change paragraph breaks (^p) to </p>^p<p>