
Tips.Net > WordTips Home > Files > Formatting Text Files with WordBasic
Summary: A handy WordBasic macro that helps you format e-mail messages and other text files. (This tip works with Microsoft Word 6, and Word 95.)
It is not uncommon to need to format text files in Word. For instance, you may get an e-mail message from someone that needs formatting, or you may get an ASCII file from a friend. The most common necessities in formatting such a file is to remove extra spaces or tabs from the beginning of a line, extra spaces or tabs from the end of a line, removing "reply" characters from the beginning of each line, and combining lines to make paragraphs.
Doing all this by hand is very time-consuming work, and can easily drive you batty, particularly if the file is very large. The following macro, DoASCII, should make it easier for you. It accomplishes all the tasks just recounted, and does it very quickly. This version is designed to work with Word 6 or Word 95:
Sub MAIN
StartOfDocument
EditFindClearFormatting
EditReplaceClearFormatting
EditReplace .Find = "^p^w", .Replace = "^p", .Direction = 0, _
.MatchCase = 0, .WholeWord = 0, .PatternMatch = 0, _
.SoundsLike = 0, .ReplaceAll, .Format = 0, .FindAllWordForms = 0
EditReplace .Find = "^p> ", .ReplaceAll
EditReplace .Find = "^p> ", .ReplaceAll
EditReplace .Find = "^p> ", .ReplaceAll
EditReplace .Find = "^p> ", .ReplaceAll
EditReplace .Find = "^p^w", .ReplaceAll
EditReplace .Find = "^w^p", .ReplaceAll
EditReplace .Find = "^p^p", .Replace = "[{}]", .ReplaceAll
EditReplace .Find = "^p", .Replace = " ", .ReplaceAll
EditReplace .Find = "[{}]", .Replace = "^p", .ReplaceAll
End Sub
You should note that this macro will replace up to four levels of "> " characters put at the beginning of a line. It also assumes that the only place you want paragraph breaks are those places where a blank line exists.
Tip #1267 applies to Microsoft Word versions: 6 95
Ultimate Library! An amazing resource that brings together, in one place, the collected knowledge of everything ever published in WordTips. The library combines two powerful elements to make you more productive: solutions and convenience. Here's where you get your own copy of everything ever published in WordTips.
Check out WordTips Ten-Year Library today!
Have thousands of WordTips at your fingertips, on your own system. Answer your own questions or help support others. (more information...)
Ask a Word Question
Make a Comment
Beauty Tips
Bugs and Pests Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pet Tips
Word2007 Tips
WordTips