
Tips.Net > WordTips Home > Formatting > Paragraph Formatting > Automatically Formatting an ASCII File
Summary: Import a file from a source external to Word, and you can end up with a formatting nightmare. One big step is to remove any extra hard returns in the document. The macro in this tip is very helpful in this regard. (This tip works with Microsoft Word 97, Word 2000, Word 2002, Word 2003, and Word 2007.)
One of the biggest problems in formatting what was previously an ASCII file is modifying it so there are only hard returns at the end of paragraphs. Most ASCII files have a hard return at the end of every line of the file, and two hard returns at the end of every paragraph. If you have an ASCII file that is formatted like this, such as something you downloaded off the Internet, the following macro will be invaluable. It formats an entire file so there are only hard returns at the end of paragraphs.
Sub ConvertASCII()
Fmt "^p^p", "{|}"
Fmt "^p", " {@}"
Fmt " {@}", " "
Fmt "{@}", " "
Fmt "{|}", "^p"
End Sub
Sub Fmt(sFromWord, sToWord)
Set myRange = ActiveDocument.Content
myRange.Find.ClearFormatting
myRange.Find.Execute FindText:=sFromWord, _
ReplaceWith:=sToWord, MatchCase:=0, _
Replace:=wdReplaceAll
End Sub
You should run the ConvertASCII macro. It calls the Fmt macro several times to replace various combinations of return characters to get toward the desired result.
Tip #187 applies to Microsoft Word versions: 97 2000 2002 2003 2007
Create and Merge! Using Word's mail merge tool you can quickly and easily combine data from a variety of data sources to create great individualized documents that incorporate your data in ways that you control. WordTips: Mail Merge Magic is an invaluable source for learning how to harness the full power of Word's mail merging capabilities.
Check out WordTips: Mail Merge Magic today!
Thousands of WordTips, available for immediate download. Have all the Microsoft Word info you need, right at your fingertips. (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