Dear Experts:

I came up with the following macro to insert a nonbreaking space
between the =A7-symbol followed by any number of blank spaces (usually
one or two) and any following number. For example:
=A7nonbreakingspace138 (=A7 138).
It is running fine. See the code below.

Sub InsertNonBreakingSpace()

Dim rngStory As Range

For Each rngStory In ActiveDocument.StoryRanges

With rngStory.Find
.Text =3D "(=A7) {1;}([0-9])"
.MatchWildcards =3D True
.Execute Replace:=3DwdReplaceAll, ReplaceWith:=3D"\1^s\2"
End With

Next rngStory

End Sub


But now I would like to expand the macro to insert a nonbreaking
space not only after the =A7-symbol but also after the number (can be a
number with one, two, three, four etc. digits) that immediatley
follows the first nonbreaking space as in:

=A7-NonbreakingSpace-138-NonbreakingSpace-Corporate Code (=A7 138
Corporate Code)

I did not manage to re-write my code to include the second nonbreaking
space.

Help is appreciated. Thank you very much in advance.

Re: Include several nonbreaking spaces in an expression by andreas

andreas
Tue Jun 26 15:05:55 CDT 2007

On 26 Jun., 15:28, andreas <andreas.her...@gmx.de> wrote:
> Dear Experts:
>
> I came up with the following macro to insert a nonbreaking space
> between the =A7-symbol followed by any number of blank spaces (usually
> one or two) and any following number. For example:
> =A7nonbreakingspace138 (=A7 138).
> It is running fine. See the code below.
>
> Sub InsertNonBreakingSpace()
>
> Dim rngStory As Range
>
> For Each rngStory In ActiveDocument.StoryRanges
>
> With rngStory.Find
> .Text =3D "(=A7) {1;}([0-9])"
> .MatchWildcards =3D True
> .Execute Replace:=3DwdReplaceAll, ReplaceWith:=3D"\1^s\2"
> End With
>
> Next rngStory
>
> End Sub
>
> But now I would like to expand the macro to insert a nonbreaking
> space not only after the =A7-symbol but also after the number (can be a
> number with one, two, three, four etc. digits) that immediatley
> follows the first nonbreaking space as in:
>
> =A7-NonbreakingSpace-138-NonbreakingSpace-Corporate Code (=A7 138
> Corporate Code)
>
> I did not manage to re-write my code to include the second nonbreaking
> space.
>
> Help is appreciated. Thank you very much in advance.


Hello everybody,

found out myself, so no need for you to come up with a solution
anymore:

Sub InsertNonBreakingSpace()

Dim rngStory As Range

For Each rngStory In ActiveDocument.StoryRanges



With rngStory.Find
.Text =3D "(=A7) {1;}([0-9]@) ([a-zA-Z])"
.MatchWildcards =3D True
.Execute Replace:=3DwdReplaceAll, ReplaceWith:=3D"\1^s\2^s\3"
End With

Next rngStory


End Sub