Group: microsoft.public.word.vba.general
From: andreas
Date: Sunday, March 30, 2008 3:47 PM
Subject: =?ISO-8859-1?Q?Re=3A_Insertion_of_nonbreaking_space_between_a_number_?= =?ISO-8859-1?Q?and_the_degrees_character_=28=B0_ANSI_value_176=29?=

On Mar 30, 2:55=A0am, Helmut Weber wrote:
> Hi Andreas,
>
> in case that there is only one ordinary space chr(32)
> between a digit and "=B0C":
>
> Sub Test002()
> Dim rDcm As Range
> Set rDcm =3D ActiveDocument.Range
> With rDcm.Find
> =A0 =A0.Text =3D "([0-9]) (=B0C)"
> =A0 =A0.Replacement.Text =3D "\1^0160\2"
> =A0 =A0.MatchWildcards =3D True
> =A0 =A0.Execute Replace:=3DwdReplaceAll
> End With
> End Sub
>
> In case that there is nothing between
> the digit and "=B0C" or more than one ordinary space,
> things get complicated.
>
> --
>
> Greetings from Bavaria, Germany
>
> Helmut Weber, MVP WordVBA
>
> Vista Small Business, Office XP


Hey Helmut,

thank you for your help. You may remember, some months ago I posted a
similiar question on the insertion of nonbreaking spaces between Page
and the Page number (e.g. S. 37). I also wanted the code to show me
the instances of the insertions made. You and Greg Maxey came up with
a superb solution (see below). I now just slightly re-wrote that
former code for my latest requirement. It is running just fine.

Thank you so much for your terrific help. Regards, Andreas



Sub NonBreakingSpacesDegree()
'Courtesy by Greg Maxey, and Helmut Weber (Google Groups)
Dim rngStory As Range
Dim i As Long

If MsgBox("Would you like to insert a nonbreaking space between a
number and the following degrees Character" _
, vbYesNo, "Insertion of nonbreaking space between the number and
Degree Celsius Sign (5 =B0C)") =3D vbYes Then


For Each rngStory In ActiveDocument.StoryRanges
Do
With rngStory.Find
.Text =3D "([0-9]) {1;}(=B0C)"
.MatchWildcards =3D True
.Replacement.Text =3D "\1^0160\2"
While .Execute(Replace:=3DwdReplaceOne)
i =3D i + 1
rngStory.Collapse wdCollapseEnd
Wend
End With
Set rngStory =3D rngStory.NextStoryRange
Loop Until rngStory Is Nothing
Next rngStory
If i > 0 Then
MsgBox "Replacement made " & i & " time(s)."
Else
MsgBox "Keine Grad-Zeichen vorhanden oder die gesch=FCtzten
Leerzeichen wurden schon gesetzt!", vbOKOnly, "Es wurden keine
Ersetzungen vorgenommen!"
End If
End If

Call NonBreakingSpacesDegree2

End Sub

Sub NonBreakingSpacesDegree2()
'Greg Maxey, Google along with Helmut Weber
Dim rngStory As Range
Dim i As Long

If MsgBox("Would you like to insert a nonbreaking space between a
number followed by any number of spaces and the ensuing degrees
Character" _
, vbYesNo, "Insertion of nonbreaking space between the number and
Degree Celsius Sign (5=B0C)") =3D vbYes Then


For Each rngStory In ActiveDocument.StoryRanges
Do
With rngStory.Find
.Text =3D "([0-9])(=B0C)"
.MatchWildcards =3D True
.Replacement.Text =3D "\1^s\2"
While .Execute(Replace:=3DwdReplaceOne)
i =3D i + 1
rngStory.Collapse wdCollapseEnd
Wend
End With
Set rngStory =3D rngStory.NextStoryRange
Loop Until rngStory Is Nothing
Next rngStory
If i > 0 Then
MsgBox "Replacement made " & i & " time(s)."
Else
MsgBox "Keine Grad-Zeichen vorhanden oder Gesch=FCtzte Leerzeichen
wurden schon gesetzt!", vbOKOnly, "Es wurden keine Ersetzungen
vorgenommen!"
End If
End If

End Sub

Safety Articles | Usenet Groups | Usenet News | Bluegrass