Distinguishing hard spaces from regular spaces

J

John Doue

Hi,

Since in French, characters (;:?!) need an unbreakable space before
them, I frequnetly run a routine like this one for each of them:

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = " ;"
.Replacement.Text = "^s;"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.Mat chWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

which gets the job done.

However, I was recently remarked by a fellow translator that the revised
translations I was returning to him (with track changes on screen)
showed that all the properly hardspaced characters he had inserted had
been replaced by ... properly hardspaced characters.

Looking into the issue, I realized (I had forgotten about this) that
Word considers a "hard space" also as a "space" ... and therefore, my
macro needlessly replaces them. Which shows on screen when tracking
changes in on while running the macro.

Any ideas how to work around this?

Best regards
 
J

Jay Freedman

Hi John,

Just change to .MatchWildcards = True.

A wildcard search using a space character in the Find.Text expression won't
match a nonbreaking space. Everything else remains the same. See
http://www.gmayor.com/replace_using_wildcards.htm for more about wildcards.
The article does note that wildcard searches are case-sensitive, but this
little tidbit is missing.

A warning to anyone who's about to suggest using a wildcard Find.Text
expression of " ([;:\!\?]) to catch all the punctuation in one execution,
and a Replacement.Text expression of " \1" -- I tried it, and it doesn't
work. There's a bug that reverses the replacement when you use the \1 code,
so space+punctuation is replaced by punctuation+nonbreaking space. I first
ran into that bug in Word 2007 Beta 1, but it's also in Word 2003 and
probably earlier versions.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
J

John Doue

Jay said:
Hi John,

Just change to .MatchWildcards = True.

A wildcard search using a space character in the Find.Text expression won't
match a nonbreaking space. Everything else remains the same. See
http://www.gmayor.com/replace_using_wildcards.htm for more about wildcards.
The article does note that wildcard searches are case-sensitive, but this
little tidbit is missing.

A warning to anyone who's about to suggest using a wildcard Find.Text
expression of " ([;:\!\?]) to catch all the punctuation in one execution,
and a Replacement.Text expression of " \1" -- I tried it, and it doesn't
work. There's a bug that reverses the replacement when you use the \1 code,
so space+punctuation is replaced by punctuation+nonbreaking space. I first
ran into that bug in Word 2007 Beta 1, but it's also in Word 2003 and
probably earlier versions.
Jay,

Thanks for your suggetion. I run into a problem applying it to a "?"
search since Word deems the search invalid (because ? means any
character in this case). Any idea for this character?
 
J

Jay Freedman

John said:
Jay said:
Hi John,

Just change to .MatchWildcards = True.

A wildcard search using a space character in the Find.Text
expression won't match a nonbreaking space. Everything else remains
the same. See http://www.gmayor.com/replace_using_wildcards.htm for
more about wildcards. The article does note that wildcard searches
are case-sensitive, but this little tidbit is missing.

A warning to anyone who's about to suggest using a wildcard Find.Text
expression of " ([;:\!\?]) to catch all the punctuation in one
execution, and a Replacement.Text expression of " \1" -- I tried it,
and it doesn't work. There's a bug that reverses the replacement
when you use the \1 code, so space+punctuation is replaced by
punctuation+nonbreaking space. I first ran into that bug in Word
2007 Beta 1, but it's also in Word 2003 and probably earlier
versions.
Jay,

Thanks for your suggetion. I run into a problem applying it to a "?"
search since Word deems the search invalid (because ? means any
character in this case). Any idea for this character?

For any of the special characters, to find the literal character you must
place a backslash before it. So for this one the search expression is

.Text = " \?"

The same will be true for the exclamation point.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 

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