Re: find and replace text that is not in a table
- From: MikeB77 <MikeB77@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 17 Dec 2007 01:48:00 -0800
Thanks Greg. my goal is to make it either single or double spacing after
sentences (proportional font or not). The more I think about it I'm not that
sure why I'm worried about tables - I think I've formatted some so poorly in
the past that I'm keen not to mess with past messes. With Helmut's individual
test I can also open this up to including/excluding headings and then do the
spaces between words more easily.
"Greg Maxey" wrote:
Mike,.
I concur with Helmut. I have the following code posted on my website:
Sub TwoSpacesAfterSentence2()
Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
.ClearFormatting
.MatchWildcards = True
.Text = "(*{2})([.\!\?]) ([A-Z])"
.Replacement.Text = "\1\2 \3" 'Two spaces between 2 and \
.Execute Replace:=wdReplaceAll
.Text = "([.\!\?]) {3,}([A-Z])"
.Replacement.Text = "\1 \2"
.Execute Replace:=wdReplaceAll
'This should prevent most cases of improper double spacing
'in names (e.g., F. Lee Bailey, George W. Bush, etc.)
.Text = "([!A-Z][A-Z].) ([A-Z])" 'Two spaces between ) and (
.Replacement.Text = "\1 \2"
.Execute Replace:=wdReplaceAll
End With
End Sub
I don't know why you don't want to process tables, but if it is due to
having a bunch of names or something similiar in the cells then this may
work for you. Regardless you need to be aware that your code as written
code adversly effect the look of names like John F. Kennedy.
--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
"MikeB77" <MikeB77@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:A62D31FE-C8CA-4163-8DDD-35DD246E1D9B@xxxxxxxxxxxxxxxx
Hello
I'm trying to tidy up word text by removing or applying double spaces
after
sentences. the selected text to tidy MAY include tables But I don't want
to
change text that is in a tables - just text outside tables.
How can I limit .find to non-table text.? I've stumbled across
range.information(wdWithInTable) as a lead but can weave this in.
Or could I redefine my myRng text to exclude tables?
my snippets so far:
Sub mySub
'set myRng from selection or story.. it depends
'get A which is either ' ' or ' ' depending on if proportional font or
not
'call my function (below) for various sentence ending punctuation:
MakeChanges4(myRng, ".", ".", A)
MakeChanges4(myRng, ":", ":", A)
MakeChanges4(myRng, "[\!]", "!", A)
MakeChanges4(myRng, "[\?]", "?", A)
end Sub
Private Function MakeChanges4(myRange As Range, findPunct As String, punct
As String, newSpace As String)
sp = "[ ]{1,}" 'spaces string using wildcard format
myRange.Find.ClearFormatting
' MY QUESTION HERE - HOW TO LIMIT THIS TO REPLACE ONLY NON TABLE TEXT
myRange.Find.Execute FindText:=findPunct & sp, _
ReplaceWith:=punct & newSpace, MatchCase:=0, _
Replace:=wdReplaceAll, MatchWildcards:=True
End Function
Thanks in advance
Mike
- References:
- Re: find and replace text that is not in a table
- From: Greg Maxey
- Re: find and replace text that is not in a table
- Prev by Date: Re: Word vba that copies Excel graph into Word doc
- Next by Date: Re: Restart list numbering in Word 2007
- Previous by thread: Re: find and replace text that is not in a table
- Next by thread: Re: Open Print Dialog
- Index(es):
Relevant Pages
|