
Tips.Net > WordTips Home > Formatting > Underlining Quoted Text
Summary: Do you have a document in which you need to convert all the quoted text (text surrounded by quotes) to underlined text? If so, then the macro presented in this tip will be a huge timesaver for you. (This tip works with Microsoft Word 97, Word 2000, Word 2002, and Word 2003.)
For some documents, you may have the need to underline information within quotes. For instance, for some legal documents you may need to find all material surrounded by quotes, and then make the information between the quotes underlined. This is different from regular prose writing, where you would use either underlines or quotes, but not both.
If you have a need to search for all quoted text and make it underlined, you can use the following macro. It searches for quotes, and when it finds one, it underlines everything up to the next quote. Note that it will not actually underline the quote marks themselves.
Sub UnderlineQuoted()
Dim bSearchAgain As Boolean
Selection.HomeKey Unit:=wdStory
bSearchAgain = True
' start of loop
While bSearchAgain
' set up find of first of quote pair
With Selection.Find
.ClearFormatting
.Text = Chr(34)
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Execute
End With
If Selection.Find.Found Then
Selection.MoveRight Unit:=wdCharacter, Count:=1
' switch on selection extend mode
Selection.Extend
' find second quote of this pair
Selection.Find.Execute
If Selection.Find.Found Then
Selection.MoveLeft Unit:=wdCharacter, Count:=1
' make it underlined
Selection.Font.Underline = True
' move past end of what was just changed
Selection.Collapse Direction:=wdCollapseEnd
Selection.MoveRight Unit:=wdCharacter, Count:=1
Else
bSearchAgain = False
End If
Else
bSearchAgain = False
End If
Wend
End Sub
Tip #1589 applies to Microsoft Word versions: 97 2000 2002 2003
Find and Replace Almost Anything! Learn the ins and outs of the powerful search engines available in Word. Learn to search for and replace text, formatting, graphics, and special characters the easy way with WordTips: Find and Replace.
The real power behind Word's best documents lies in understanding styles and templates. Learn the key to more powerful document creation. (more information...)
Ask a Word Question
Make a Comment
Beauty Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Pet Tips
Word2007 Tips
WordTips