Written by Allen Wyatt (last updated October 1, 2020)
This tip applies to Word 2007, 2010, and 2013
Sandy asked how to find all text between quotation marks and format it to be bold. The solution needs to be able to handle multiple words between the quote marks—entire phrases that need to be bold. This is an interesting question, and there are several ways that it can be approached.
One approach is to use Word's powerful Find and Replace feature to do just what you need. Follow these steps:
Figure 1. The Replace tab of the Find and Replace dialog box.
["|"]*["|"]
Notice that when Word is done with this search and replace, it will have bolded not only the text within the quotes, but the quotes themselves. If you want to change the quotes back to normal, you can do another wildcard search, this time looking for simply ["|"|"] (step 2, with the last two quotes being opening and closing smart quotes) and replacing it with Not Bold formatting (step 5).
It is interesting to note that you must search for ["|"]*["|"] and not simply for "*". The reason for this is quite simple. If you are getting your documents (the ones you are formatting) from someone else, you don't know right off the bat if they used smart quotes, regular quotes, or a combination of both. By using the brackets surrounding the two types of quotes on both sides of a vertical bar, you are telling Word to match with either type of opening or closing quote. When you have Use Wildcards selected, Word discriminates between regular and smart quotes. (It doesn't discriminate if you are using Search and Replace without wildcards turned on.)
If you need to do quite a bit of formatting of information between quotes in this manner, the best bet is to create a macro that you can assign to a shortcut key or to the Quick Access Toolbar. Perhaps the easiest way is to simply use the macro recorder to record the above steps. If you prefer, you can utilize the following macro to do the trick:
Sub BoldBetweenQuotes() ' base for a quotes finding macro Dim blnSearchAgain As Boolean ' move to start of doc Selection.HomeKey Unit:=wdStory ' start of loop Do ' 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 bold Selection.Font.Bold = True Selection.Collapse Direction:=wdCollapseEnd Selection.MoveRight Unit:=wdCharacter, Count:=1 blnSearchAgain = True Else blnSearchAgain = False End If Else blnSearchAgain = False End If Loop While blnSearchAgain End Sub
Note:
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (8436) applies to Microsoft Word 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Word here: Automatically Formatting Text within Quotes.
Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!
Word gives you control over how your text appears on the page. This includes adjusting how close letters are to each ...
Discover MoreA quick little shortcut can help you easily step through different font sizes for whatever text you've selected. Word ...
Discover MoreOne of the ways that Word allows you to format text is to underline it. However, you have virtually no control on where ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
2021-02-24 19:48:32
Siva
In some programming language IDEs (e.g. Pycharm) one can select a word or phrase and press the single or double quote, or any type of bracket, which will enclose the selected text in quotes or brackets. Is it possible with Word?
2017-02-27 13:38:42
lisagd
As a copy editor, I ask all of you not to use quotes to make a word stand out. Use bold, italics, font color, or all caps instead. Quotes serve several specific purposes, and highlighting a word is not one of them.
2016-05-17 16:14:53
Lorraine
How to add underlying to automatically formatting text within quotes?
Thanks.
2015-06-03 07:49:35
Mary
I realized what I had done incorrectly in copying your macro into a "create" a macro and it worked. So now I use Alt I to run it and it works. Thanks. Took a few hours to figure out what I was doing incorrectly, but all is well.
2015-06-02 08:05:06
Ken Endacott
To fix the macro so that it finds all occurrences of quote pairs add the line:
Selection.ExtendMode = False
just before the line:
blnSearchAgain = True
However, the macro will only find straight quotes. The following macro will find both straight and curley quote pairs. Beware, if there is a single quote in the document then it will upset the finding of pairs.
Sub BoldBetweenQuotes()
' quotes finding macro
Dim blnSearchAgain As Boolean
' move to start of doc
Selection.HomeKey unit:=wdStory
' start of loop
Do
With Selection.Find
.ClearFormatting
.Text = "[" & Chr(34) & "|" & Chr(147) & "]*[" & Chr(34) & "|" & Chr(148) & "]"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
.Execute
End With
If Selection.Find.Found Then
Selection.MoveStart unit:=wdCharacter, Count:=1
Selection.MoveEnd unit:=wdCharacter, Count:=-1
Selection.Font.Bold = True
Selection.Collapse Direction:=wdCollapseEnd
Selection.MoveRight unit:=wdCharacter, Count:=1
blnSearchAgain = True
Else
blnSearchAgain = False
End If
Loop While blnSearchAgain
End Sub
2015-06-01 14:50:32
Mary
Hi: I tried to copy your macro you used for the bold text between quotes. I gave it a name, the record button came on I pasted your program macro to it and stopped recording. When I tried to run it, nothing happened. It actually gave me a copy of the macro I copied from your site. I used the Alt O as my keyboard shortcut. I tried copying your code using mouse and did not work, then I used Ctrl A to highlight whole code and paste in macro box and nothing happened. So I am doing something incorrectly. Any help please.
2015-04-14 12:32:24
Lorraine
I tried the macro and it only bolds one word in the document.
2013-09-15 09:31:57
Ferdinand Spek
Hello Alan,
I found your website through a search for my problem. Excellent website by the way!
The problem I am having is that I have a document with lots of text between quotes (signal names actually of varying word lengths) and I want to extract them to a separate document. A colleague of mine made a macro to extract acronyms to a new document, so I was thinking about a combination of this macro and the other.
I tried to combine the macros but can't get it to work. I tried your macro on a separate document, but it seems to make only the first quote bold. Is that correct?
Below my macro so far, any help is appreciated.
Best regards, Ferdinand Spek
Sub ExportBetweenQuotes()
Dim oDoc_Source As Document
Dim oDoc_Target As Document
Dim strListSep As String
Dim strQuote As String
Dim oTable As Table
Dim oRange As Range
Dim n As Long
Dim strAllFound As String
Set oDoc_Source = ActiveDocument
'Create new document for acronyms
Set oDoc_Target = Documents.Add
With oDoc_Target
'Make sure document is empty
.Range = ""
'Insert a table with room for acronym and definition
Set oTable = .Tables.Add(Range:=.Range, NumRows:=2, NumColumns:=2)
With oTable
'Format the table a bit
'Insert headings
.Cell(1, 1).Range.Text = "Quotation"
.Cell(1, 2).Range.Text = "Definition"
'Set row as heading row
.Rows(1).HeadingFormat = True
.Rows(1).Range.Font.Bold = True
.PreferredWidthType = wdPreferredWidthPercent
.Columns(1).PreferredWidth = 50
.Columns(2).PreferredWidth = 50
End With
End With
With oDoc_Source
' base for a quotes finding macro
Dim blnSearchAgain As Boolean
' move to start of doc
Selection.HomeKey Unit:=wdStory
' start of loop
Do
' 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 bold
'Continue while found
strQuote = Selection.Text
'Insert in target doc
'If strQuote is already in strAllFound, do not add again
If InStr(1, strAllFound, "#" & strQuote & "#") = 0 Then
'Add new row in table from second acronym
If n > 1 Then oTable.Rows.Add
'Was not found before
strAllFound = strAllFound & strQuote & "#"
'Insert in column 1 in oTable
'Compensate for heading row
With oTable
'Insert acronym in column 1
.Cell(n + 1, 1).Range.Text = strQuote
'Insert definition in column 2
.Cell(n + 1, 2).Range.Text = "Temp"
End With
n = n + 1
End If
' Selection.Font.Bold = True
Selection.Collapse Direction:=wdCollapseEnd
Selection.MoveRight Unit:=wdCharacter, Count:=1
blnSearchAgain = True
Else
blnSearchAgain = False
End If
Else
blnSearchAgain = False
End If
Loop While blnSearchAgain
'Sort the acronyms alphabetically
With Selection
.Sort ExcludeHeader:=True, FieldNumber:="Column 1", SortFieldType:=wdSortFieldAlphanumeric, SortOrder:=wdSortOrderAscending
.HomeKey (wdStory)
End With
End With
'Clean up
Set oDoc_Source = Nothing
Set oDoc_Target = Nothing
Set oTable = Nothing
MsgBox "Finished extracting " & n - 1 & " quote(s) to a new document."
End Sub
Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2023 Sharon Parq Associates, Inc.
Comments