Re: find and replace text that is not in a table



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



.



Relevant Pages

  • Re: Changing fonts throughout document including headers footers and footnotes
    ... Greg, what is your correct e-mail address? ... Public Sub FindReplaceAnywhere() ... Dim pReplaceTxt As String ... For Each rngStory In ActiveDocument.StoryRanges ...
    (microsoft.public.word.vba.general)
  • Re: Prompt to Save When Closing
    ... Thanks, Greg. ... > Public Sub BatchToggleEmbedSmartTabs() ... >Dim PathToUse As String ...
    (microsoft.public.word.docmanagement)
  • Re: Backing up my folders
    ... Greg, you could try this. ... Sub Archive(YourDir As String) ... Dim ArchiveDir As String ...
    (microsoft.public.excel.programming)
  • Re: Restrict Find&Repalce to Selected Text
    ... Greg Maxey/Word MVP ... >> Sub FRinSelectionOnly() ... >> Dim oRg As Range ... >> oRg.InRangeLoop ...
    (microsoft.public.word.vba.general)
  • Re: Passing a value to a macro
    ... Hi Greg, the two most commonly used are Let ... Dim strIncomingPath as String 'at the module level ... Public Property Let FilePathAs String) ... To retrieve in the calling code: ...
    (microsoft.public.word.vba.userforms)