Include several nonbreaking spaces in an expression

A

andreas

Dear Experts:

I came up with the following macro to insert a nonbreaking space
between the §-symbol followed by any number of blank spaces (usually
one or two) and any following number. For example:
§nonbreakingspace138 (§ 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 = "(§) {1;}([0-9])"
.MatchWildcards = True
.Execute Replace:=wdReplaceAll, ReplaceWith:="\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 §-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:

§-NonbreakingSpace-138-NonbreakingSpace-Corporate Code (§ 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.
 
A

andreas

Dear Experts:

I came up with the following macro to insert a nonbreaking space
between the §-symbol followed by any number of blank spaces (usually
one or two) and any following number. For example:
§nonbreakingspace138 (§ 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 = "(§) {1;}([0-9])"
.MatchWildcards = True
.Execute Replace:=wdReplaceAll, ReplaceWith:="\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 §-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:

§-NonbreakingSpace-138-NonbreakingSpace-Corporate Code (§ 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 = "(§) {1;}([0-9]@) ([a-zA-Z])"
.MatchWildcards = True
.Execute Replace:=wdReplaceAll, ReplaceWith:="\1^s\2^s\3"
End With

Next rngStory


End Sub
 

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