I have a procedure that eliminates all extra spaces (i.e., more than 2 in a
row) from the document. However, there is one particular style which has a
mono type, and spaces are used to line things up. I want my routine to
search the document and ignore only the paragraphs formatted in that style.
Here is the routine, and a representation of what I want to do (but which
doesn't work):

Sub DeleteExtraSpaces()
'
' Replaces any instance of 3 or more spaces with 2 spaces only.
'
If Not TrackChanges Then
With ActiveDocument.Content.Find
.ClearFormatting
.Replacement.ClearFormatting
.Font.Underline = wdUnderlineNone
.Style <> "BriefXScript" ' This is what I want to do, but get an
error.
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
.Execute FindText:=" {3,}", ReplaceWith:=" ", Replace:=wdReplaceAll
.ClearFormatting
End With
End If
End Sub

Thanks in advance!

Re: Find Replace w negated option by Jezebel

Jezebel
Sun Sep 10 22:46:21 CDT 2006

.Style is a property of the Find object, so it takes a value not a function.
Unfortunately there are no negation functions (other than the wildcard not)
for find, so you need to work paragraph by paragraph --

Dim pPar As Word.Paragraph

For Each pPar In ActiveDocument.Paragraphs
If pPar.Style <> "BriefXScript" Then
With pPar.Range.Find
.MatchWildcards = True
.Execute FindText:=" {3,}", ReplaceWith:=" ",
Replace:=wdReplaceAll
End With
End If
Next





"automandc" <automandc@discussions.microsoft.com> wrote in message
news:387FCEC6-97FD-425C-9CBB-699ABDEF0BF8@microsoft.com...
>I have a procedure that eliminates all extra spaces (i.e., more than 2 in a
> row) from the document. However, there is one particular style which has
> a
> mono type, and spaces are used to line things up. I want my routine to
> search the document and ignore only the paragraphs formatted in that
> style.
> Here is the routine, and a representation of what I want to do (but which
> doesn't work):
>
> Sub DeleteExtraSpaces()
> '
> ' Replaces any instance of 3 or more spaces with 2 spaces only.
> '
> If Not TrackChanges Then
> With ActiveDocument.Content.Find
> .ClearFormatting
> .Replacement.ClearFormatting
> .Font.Underline = wdUnderlineNone
> .Style <> "BriefXScript" ' This is what I want to do, but get an
> error.
> .Forward = True
> .Wrap = wdFindContinue
> .MatchWildcards = True
> .Execute FindText:=" {3,}", ReplaceWith:=" ",
> Replace:=wdReplaceAll
> .ClearFormatting
> End With
> End If
> End Sub
>
> Thanks in advance!



Re: Find Replace w negated option by automandc

automandc
Sun Sep 10 22:53:01 CDT 2006

Thanks, that's what I was afraid of! Still, the solution isn't too
complicated.

"Jezebel" wrote:

> ..Style is a property of the Find object, so it takes a value not a function.
> Unfortunately there are no negation functions (other than the wildcard not)
> for find, so you need to work paragraph by paragraph --
>
> Dim pPar As Word.Paragraph
>
> For Each pPar In ActiveDocument.Paragraphs
> If pPar.Style <> "BriefXScript" Then
> With pPar.Range.Find
> .MatchWildcards = True
> .Execute FindText:=" {3,}", ReplaceWith:=" ",
> Replace:=wdReplaceAll
> End With
> End If
> Next
>
>
>
>
>
> "automandc" <automandc@discussions.microsoft.com> wrote in message
> news:387FCEC6-97FD-425C-9CBB-699ABDEF0BF8@microsoft.com...
> >I have a procedure that eliminates all extra spaces (i.e., more than 2 in a
> > row) from the document. However, there is one particular style which has
> > a
> > mono type, and spaces are used to line things up. I want my routine to
> > search the document and ignore only the paragraphs formatted in that
> > style.
> > Here is the routine, and a representation of what I want to do (but which
> > doesn't work):
> >
> > Sub DeleteExtraSpaces()
> > '
> > ' Replaces any instance of 3 or more spaces with 2 spaces only.
> > '
> > If Not TrackChanges Then
> > With ActiveDocument.Content.Find
> > .ClearFormatting
> > .Replacement.ClearFormatting
> > .Font.Underline = wdUnderlineNone
> > .Style <> "BriefXScript" ' This is what I want to do, but get an
> > error.
> > .Forward = True
> > .Wrap = wdFindContinue
> > .MatchWildcards = True
> > .Execute FindText:=" {3,}", ReplaceWith:=" ",
> > Replace:=wdReplaceAll
> > .ClearFormatting
> > End With
> > End If
> > End Sub
> >
> > Thanks in advance!
>
>
>

Re: Find Replace w negated option by Tony

Tony
Mon Sep 11 01:40:10 CDT 2006

Or you could change the spaces in BriefXScript to, say, hard spaces, and
then back again afterwards ..

Sub DeleteExtraSpaces()
'
' Replaces any instance of 3 or more spaces with 2 spaces only.
'
If Not TrackChanges Then
With ActiveDocument.Content.Find
.ClearFormatting
.Replacement.ClearFormatting
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True

.Style = "BriefXScript"
.Execute FindText:=" ", ReplaceWith:=Chr(160),
Replace:=wdReplaceAll
.ClearFormatting
.Font.Underline = wdUnderlineNone
.Execute FindText:=" {3,}", ReplaceWith:=" ",
Replace:=wdReplaceAll
.ClearFormatting
.Style = "BriefXScript"
.Execute FindText:=Chr(160), ReplaceWith:=" ",
Replace:=wdReplaceAll
End With
End If
End Sub


--
Enjoy,
Tony

"Jezebel" <warcrimes@whitehouse.gov> wrote in message
news:#2FCeTV1GHA.3900@TK2MSFTNGP05.phx.gbl...
> .Style is a property of the Find object, so it takes a value not a
function.
> Unfortunately there are no negation functions (other than the wildcard
not)
> for find, so you need to work paragraph by paragraph --
>
> Dim pPar As Word.Paragraph
>
> For Each pPar In ActiveDocument.Paragraphs
> If pPar.Style <> "BriefXScript" Then
> With pPar.Range.Find
> .MatchWildcards = True
> .Execute FindText:=" {3,}", ReplaceWith:=" ",
> Replace:=wdReplaceAll
> End With
> End If
> Next
>
>
>
>
>
> "automandc" <automandc@discussions.microsoft.com> wrote in message
> news:387FCEC6-97FD-425C-9CBB-699ABDEF0BF8@microsoft.com...
> >I have a procedure that eliminates all extra spaces (i.e., more than 2 in
a
> > row) from the document. However, there is one particular style which
has
> > a
> > mono type, and spaces are used to line things up. I want my routine to
> > search the document and ignore only the paragraphs formatted in that
> > style.
> > Here is the routine, and a representation of what I want to do (but
which
> > doesn't work):
> >
> > Sub DeleteExtraSpaces()
> > '
> > ' Replaces any instance of 3 or more spaces with 2 spaces only.
> > '
> > If Not TrackChanges Then
> > With ActiveDocument.Content.Find
> > .ClearFormatting
> > .Replacement.ClearFormatting
> > .Font.Underline = wdUnderlineNone
> > .Style <> "BriefXScript" ' This is what I want to do, but get an
> > error.
> > .Forward = True
> > .Wrap = wdFindContinue
> > .MatchWildcards = True
> > .Execute FindText:=" {3,}", ReplaceWith:=" ",
> > Replace:=wdReplaceAll
> > .ClearFormatting
> > End With
> > End If
> > End Sub
> >
> > Thanks in advance!
>
>



Re: Find Replace w negated option by automandc

automandc
Mon Sep 11 01:51:01 CDT 2006

That would probably work too. I use non-breaking spaces a lot (I assume
that's what you mean by "hard space"?

I tried the paragraph-by-paragraph method, and it was definitely a lot slower.

"Tony Jollans" wrote:

> Or you could change the spaces in BriefXScript to, say, hard spaces, and
> then back again afterwards ..
>
> Sub DeleteExtraSpaces()
> '
> ' Replaces any instance of 3 or more spaces with 2 spaces only.
> '
> If Not TrackChanges Then
> With ActiveDocument.Content.Find
> .ClearFormatting
> .Replacement.ClearFormatting
> .Forward = True
> .Wrap = wdFindContinue
> .MatchWildcards = True
>
> .Style = "BriefXScript"
> .Execute FindText:=" ", ReplaceWith:=Chr(160),
> Replace:=wdReplaceAll
> .ClearFormatting
> .Font.Underline = wdUnderlineNone
> .Execute FindText:=" {3,}", ReplaceWith:=" ",
> Replace:=wdReplaceAll
> .ClearFormatting
> .Style = "BriefXScript"
> .Execute FindText:=Chr(160), ReplaceWith:=" ",
> Replace:=wdReplaceAll
> End With
> End If
> End Sub
>
>
> --
> Enjoy,
> Tony
>
> "Jezebel" <warcrimes@whitehouse.gov> wrote in message
> news:#2FCeTV1GHA.3900@TK2MSFTNGP05.phx.gbl...
> > .Style is a property of the Find object, so it takes a value not a
> function.
> > Unfortunately there are no negation functions (other than the wildcard
> not)
> > for find, so you need to work paragraph by paragraph --
> >
> > Dim pPar As Word.Paragraph
> >
> > For Each pPar In ActiveDocument.Paragraphs
> > If pPar.Style <> "BriefXScript" Then
> > With pPar.Range.Find
> > .MatchWildcards = True
> > .Execute FindText:=" {3,}", ReplaceWith:=" ",
> > Replace:=wdReplaceAll
> > End With
> > End If
> > Next
> >
> >
> >
> >
> >
> > "automandc" <automandc@discussions.microsoft.com> wrote in message
> > news:387FCEC6-97FD-425C-9CBB-699ABDEF0BF8@microsoft.com...
> > >I have a procedure that eliminates all extra spaces (i.e., more than 2 in
> a
> > > row) from the document. However, there is one particular style which
> has
> > > a
> > > mono type, and spaces are used to line things up. I want my routine to
> > > search the document and ignore only the paragraphs formatted in that
> > > style.
> > > Here is the routine, and a representation of what I want to do (but
> which
> > > doesn't work):
> > >
> > > Sub DeleteExtraSpaces()
> > > '
> > > ' Replaces any instance of 3 or more spaces with 2 spaces only.
> > > '
> > > If Not TrackChanges Then
> > > With ActiveDocument.Content.Find
> > > .ClearFormatting
> > > .Replacement.ClearFormatting
> > > .Font.Underline = wdUnderlineNone
> > > .Style <> "BriefXScript" ' This is what I want to do, but get an
> > > error.
> > > .Forward = True
> > > .Wrap = wdFindContinue
> > > .MatchWildcards = True
> > > .Execute FindText:=" {3,}", ReplaceWith:=" ",
> > > Replace:=wdReplaceAll
> > > .ClearFormatting
> > > End With
> > > End If
> > > End Sub
> > >
> > > Thanks in advance!
> >
> >
>
>
>