Replacing quotes string with italics (Word 2007)

  • Thread starter Sesquipedalian Sam
  • Start date
S

Sesquipedalian Sam

Someone sent me a text document (xyz.txt) containing several thousand
records. Almost every record contains a word of phrase enclosed in
quotes. Most of them indicate something that would have been in
italics, such as the titles of books, like

"Brian's Song"

but a few are properly quoted, like

Leroy Robert "Satchel" Paige

I would like to convert the quotes phrases to italics and remove the
quotes. Is there any wort of automated way to do this?

The kicker is that a few of them should not be converted. So, I
probably need to OK each one.

I'm thinking of something like the Replace function that lets me type
"r" to replace the current instance or "f" to skip this one and find
the next one.

Is there any way to get Replace (Ctrl-H) to do this?

Certainly, a macro can do it, but I am not slkilled enough to write
it? Any takers?

Thanks
 
F

Fumei2 via OfficeKB.com

Say you have:

Yadda yadda “Blah†whatever
Who knows “what†the heck is going on?
This sentence has no quotation marks.
This sentence “doesâ€.




Sub ReplaceQuotes()
Dim r As Range
Set r = ActiveDocument.Range

With r.Find
.ClearFormatting
.MatchWildcards = True
.Text = ChrW(8220) & "*" & ChrW(8221)
Do While .Execute(Forward:=True) = True
If MsgBox(r.Text & vbCrLf & "Replace as italics?", vbYesNo) _
= vbYes Then
With r
.Font.Italic = True
.Text = Right(Left(r.Text, Len(r.Text) - 1), _
Len(r.Text) - 2)
.Collapse 0
End With
End If
Loop
End With
End Sub

Each found instance of "xxxxxx" will display the messagebox with THAT found
instance (r.Text), and the question "Replace as italics?".

Click Yes, the quotation marks are removed, the text becomes italics.
Click No, it goes on to the next found instance of "xxxxx".

Note: because this uses a Range, each found instance does NOT, repeat NOT,
highlight (select) the found instance.

In other words, if you have the cursor on page 2, and the code finds "xxxxx"
on page 13, you will NOT see it. The text will appear on the messagebox, but
the document will NOT jump visually to it.

In this (rare) case, to help in the decision yes/no, I can see using
Selection (rather than Range) may be appropriate. You would see the found
instance in the document. In which case, use:

Sub ReplaceQuotes()
Dim r As Range
Set r = ActiveDocument.Range
Selection.HomeKey Unit:=wdStory

With Selection.Find
.ClearFormatting
.MatchWildcards = True
.Text = ChrW(8220) & "*" & ChrW(8221)
Do While .Execute(Forward:=True) = True
If MsgBox(Selection.Text & vbCrLf & "Replace as italics?", vbYesNo) _
= vbYes Then
With Selection
.Font.Italic = True
.Text = Right(Left(Selection.Text, Len(Selection.Text) - 1), _
Len(Selection.Text) - 2)
.Collapse 0
End With
End If
Loop
End With
End Sub
 
D

DeanH

Someone sent me a text document (xyz.txt) containing several thousand
records. Almost every record contains a word of phrase enclosed in
quotes. Most of them indicate something that would have been in
italics, such as the titles of books, like

   "Brian's Song"

but a few are properly quoted, like

   Leroy Robert "Satchel" Paige

I would like to convert the quotes phrases to italics and remove the
quotes. Is there any wort of automated way to do this?

The kicker is that a few of them should not be converted. So, I
probably need to OK each one.

I'm thinking of something like the Replace function that lets me type
"r" to replace the current instance or "f" to skip this one and find
the next one.

Is there any way to get Replace (Ctrl-H) to do this?

Certainly, a macro can do it, but I am not slkilled enough to write
it? Any takers?

Thanks

Open the Replace dialog, enter \”(*)\” into the Find What box, press
Ctrl+I, twice, so you get the Not Italics option. Go to the Replace
With box, don’t enter anything but press Ctrl+I to add italic format.
Click the More button and check the Wildcards box. The code will find
all text between quote marks and apply italic format. You have the Not
Italics format for the find so the search does not find previously
found quotes, just to shorten the process time. That is, as long as
you have not manually added any italics already ;-)
To remove the unwanted quote marks, turn off the Wildcards, add a
quote mark in the Find What box, press Ctrl+I, leave the Replace With
box clear and no formatting, This will remove all italic quotes in the
document.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top