[Date Prev][Date Next][Subject Prev][Subject Next][ Date Index][ Subject Index]

A macro for converting Word formatting to visible codes (Xy or HTML etc.)



Sometimes there is a need to make a manual conversion from a Word document to coded formats like Xy or HTML, then this Word macro does a good job of it. You are supposed to run it against a formatted Word document and save the result as a text file. Depending on the file type (ANSI, ASCII or Unicode) the codes put into the document may come out different, so you have to decide beforehand which file type you will be using if you want put Xy formatting codes directly in the code below. Or you can just replace the codes while in Xy. I found this macro useful for preparing third-party material for inclusion in a database.

Best regards,

Kari Eveli
LEXITEC Book Publishing (Finland)
lexitec@xxxxxxxx

*** Lexitec Online ***
Lexitec in English: http://www.lexitec.fi/english.html
Home page in Finnish: http://www.lexitec.fi/


A Word macro:
************
Sub Visible_Formatting
' based on: http://www.techsupportforum.com/forums/f57/ms-word-macro-text-formatting-450217.html
' *** scope: whole document
With ActiveDocument.Content.Find
' alternatively: selection only
' With Selection.Find
 ' *** bold
 .ClearFormatting
 .Replacement.ClearFormatting
 .Text = ""
 .Font.Bold = True
 .Replacement.Text = "^&"
 ' *** general settings
 .Forward = True
 .Wrap = wdFindContinue
 .Format = True
 .MatchCase = False
 .MatchWholeWord = False
 .MatchWildcards = False
 .MatchSoundsLike = False
 .MatchAllWordForms = False
 .Execute Replace:=wdReplaceAll
 ' *** italics
 .ClearFormatting
 .Font.Italic = True
 .Replacement.Text = "^&"
 .Execute Replace:=wdReplaceAll
' *** font information into character string codes
 .ClearFormatting
' *** syntax may be slightly different (".Font.Font.Name", I have Word 2000!) in newer
Word versions:
 .Font.Name = "Courier New"
 .Replacement.Text = "^&"
 .Execute Replace:=wdReplaceAll
End With
End Sub
***