Dear Experts:

I would like to be able to automatically insert a nonbreaking space
between all instances of a number and the character set =B0C (ANSII
Value of 176) using VBA. For example:

40 =B0C or 5 =B0C

I know how to do it using the Find And Replace Dialog Field. But I
also would like to be able to do it programmatically. The "Find.Text"
Line is enough.

Help is appreciated.


Thank you very much in advance.

Regards,

Andreas

Re: Insertion of nonbreaking space between a number and the degrees character (° ANSI value 176) by Doug

Doug
Sat Mar 29 17:45:06 PDT 2008

Recorded Code:

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "°C"
.Replacement.Text = "^s°C"
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"andreas" <andreas.hermle@gmx.de> wrote in message
news:1593959f-668c-48be-a75f-18f3fca58749@h11g2000prf.googlegroups.com...
Dear Experts:

I would like to be able to automatically insert a nonbreaking space
between all instances of a number and the character set °C (ANSII
Value of 176) using VBA. For example:

40 °C or 5 °C

I know how to do it using the Find And Replace Dialog Field. But I
also would like to be able to do it programmatically. The "Find.Text"
Line is enough.

Help is appreciated.


Thank you very much in advance.

Regards,

Andreas



Re: Insertion of nonbreaking space between a number and the degrees character (° ANSI value 176) by Helmut

Helmut
Sat Mar 29 17:55:33 PDT 2008

Hi Andreas,

in case that there is only one ordinary space chr(32)
between a digit and "°C":

Sub Test002()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = "([0-9]) (°C)"
.Replacement.Text = "\1^0160\2"
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
End Sub

In case that there is nothing between
the digit and "°C" or more than one ordinary space,
things get complicated.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP

=?ISO-8859-1?Q?Re=3A_Insertion_of_nonbreaking_space_between_a_number_?= by andreas

andreas
Sun Mar 30 13:37:57 PDT 2008

On Mar 30, 2:45=A0am, "Doug Robbins - Word MVP"
<d...@REMOVECAPSmvps.org> wrote:
> Recorded Code:
>
> =A0 =A0 Selection.Find.ClearFormatting
> =A0 =A0 Selection.Find.Replacement.ClearFormatting
> =A0 =A0 With Selection.Find
> =A0 =A0 =A0 =A0 .Text =3D "=B0C"
> =A0 =A0 =A0 =A0 .Replacement.Text =3D "^s=B0C"
> =A0 =A0 =A0 =A0 .Forward =3D True
> =A0 =A0 =A0 =A0 .Wrap =3D wdFindAsk
> =A0 =A0 =A0 =A0 .Format =3D False
> =A0 =A0 =A0 =A0 .MatchCase =3D False
> =A0 =A0 =A0 =A0 .MatchWholeWord =3D False
> =A0 =A0 =A0 =A0 .MatchWildcards =3D False
> =A0 =A0 =A0 =A0 .MatchSoundsLike =3D False
> =A0 =A0 =A0 =A0 .MatchAllWordForms =3D False
> =A0 =A0 End With
> =A0 =A0 Selection.Find.Execute Replace:=3DwdReplaceAll
>
> --
> Hope this helps.
>
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
>
> Doug Robbins - Word MVP
>
> "andreas" <andreas.her...@gmx.de> wrote in message
>
> news:1593959f-668c-48be-a75f-18f3fca58749@h11g2000prf.googlegroups.com...
> Dear Experts:
>
> I would like to be able to automatically insert a nonbreaking space
> between all instances of a number and the character set =B0C (ANSII
> Value of 176) using VBA. For example:
>
> 40 =B0C or 5 =B0C
>
> I know how to do it using the Find And Replace Dialog Field. But I
> also would like to be able to do it programmatically. The "Find.Text"
> Line is enough.
>
> Help is appreciated.
>
> Thank you very much in advance.
>
> Regards,
>
> Andreas

Dear Doug,
Thank you for the quick answer. With your information and Helmut's
previous help on a similiar code I came up with my own solution. See
my answer to Helmut. Thanks Doug. Regards, Andreas

=?ISO-8859-1?Q?Re=3A_Insertion_of_nonbreaking_space_between_a_number_?= by andreas

andreas
Sun Mar 30 13:47:06 PDT 2008

On Mar 30, 2:55=A0am, Helmut Weber <red....@t-online.de> 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