A
andreas
Dear Experts:
I would like to insert a nonbreaking space between all occurrences of
the abbreviated Page (p.) and the page number. Below macro works fine!
BUT the my message boxes do not work correctly:
1. Although there are these "p." abbreviations in my test document,
the Message box says there are no occurrences of this abbreviation
found, and to make things worse, this message box pops up 7 times (the
number of range stories, I suppose).
2. BUT strangely the macro then correctly inserts the nonbreaking
spaces between the abbreviated page number (p.) and the page number!
Hence I need somebody to re-write this code so that the message boxes
appear correctly. Thank you very much in advance for your help.
Regards, Andreas
Sub InsertNonBreakingSpaceP()
'Inserting NonBreakingSpaces between the abbreviated page character
(p.) and the page number
Dim rngStory As Range
Dim iNumberOfReplacements As Integer
If MsgBox("Would you like to insert a nonbreaking space between p." &
vbCrLf & _
"and the page number?", vbYesNo, "Insertion of nonbreaking spaces") =
vbYes Then
For Each rngStory In ActiveDocument.StoryRanges
With rngStory.Find
.Text = "<p. {1;}([0-9])"
.MatchWildcards = True
.Wrap = wdFindContinue
.Execute
End With
If Not rngStory.Find.Found Then
MsgBox "There are no abbreviations (p.) in the document",
vbOKOnly, _
"Nothing found"
Else
rngStory.Find.Execute Replace:=wdReplaceAll,
replaceWith:="p.^s\1"
End If
Next rngStory
End If
End Sub
I would like to insert a nonbreaking space between all occurrences of
the abbreviated Page (p.) and the page number. Below macro works fine!
BUT the my message boxes do not work correctly:
1. Although there are these "p." abbreviations in my test document,
the Message box says there are no occurrences of this abbreviation
found, and to make things worse, this message box pops up 7 times (the
number of range stories, I suppose).
2. BUT strangely the macro then correctly inserts the nonbreaking
spaces between the abbreviated page number (p.) and the page number!
Hence I need somebody to re-write this code so that the message boxes
appear correctly. Thank you very much in advance for your help.
Regards, Andreas
Sub InsertNonBreakingSpaceP()
'Inserting NonBreakingSpaces between the abbreviated page character
(p.) and the page number
Dim rngStory As Range
Dim iNumberOfReplacements As Integer
If MsgBox("Would you like to insert a nonbreaking space between p." &
vbCrLf & _
"and the page number?", vbYesNo, "Insertion of nonbreaking spaces") =
vbYes Then
For Each rngStory In ActiveDocument.StoryRanges
With rngStory.Find
.Text = "<p. {1;}([0-9])"
.MatchWildcards = True
.Wrap = wdFindContinue
.Execute
End With
If Not rngStory.Find.Found Then
MsgBox "There are no abbreviations (p.) in the document",
vbOKOnly, _
"Nothing found"
Else
rngStory.Find.Execute Replace:=wdReplaceAll,
replaceWith:="p.^s\1"
End If
Next rngStory
End If
End Sub