Ginstrom IT Solutions (GITS)

Doc2Html2Doc Word Macro

Download Doc2Html2Doc


Converts the current selection to an HTML string, or writes an HTML string into the document, preserving formatting.

Who might find this useful?

Word's Export as HTML function only exports the entire document as HTML, and the HTML it exports is (in)famous for its bloat and non-compliant style. If you only need to convert a fragment of the current document into HTML, or you want to produce cleaner HTML, then this macro will probably be useful to you.

If you are a VBA programmer, two functions allow you to convert to and from HTML programatically: GetSelectionAsHtml and Html2Doc. These are the core of the functionality used by TransAssist to convert text segments between Word formatting and the native HTML format used to store translation memories.

To Install

  1. Download the Doc2Html2Doc macro file.
  2. Launch Microsoft Word
  3. Press Alt + F11
    The Microsoft Visual Basic window appears.
  4. From the File menu, select Import File...

    Import macro menu selection

  5. Import the Doc2Html2Doc.bas file.
    Close the Visual Basic window.

To Use

Press Alt + F8 to get the macro window, specify one of the following macros:

  • WriteSelectionAsHtml – The currently selected Word text fragment is written on the next line as HTML.
  • WriteSelectionAsDoc – The currently selected HTML text is written on the next line with Word formatting

Next, click Run.

If you will be using a macro more frequently, then you can assign it a keyboard shortcut. To do so,

  1. Select Tools >> Customize
  2. Click Keyboard
  3. Set the "Categories" to Macros, and "Commands" to the macro you wish to assign
  4. Select "Press new shortcut key," and press your keyboard shortcut.
  5. Click Assign.