M
Mark Tangard
Hi gang. The code below is intended to remove all "optional hyphens" in
a document that aren't being "used" (that is, aren't at a line break
doing their job). It compares the vertical position of each found
hyphen with the vertical position of the character following it and
deletes the hyphen if those 2 positions are different.
It works in a small file (a page or so), and it works in a large file if
run step by step from the VBE (which of course, is too slow to provide
any benefit.). It *doesn't* work if run from the document window on a
document of any appreciable size. In that case, *all* the soft hyphens
are removed.
I've tried this code with ^31 (ascii for soft hyphen) where "^-" is
shown below (for .Text), and have tried it with and without codes
displayed. No change in either case. Any ideas?
BTW, I haven't gone batty, there's actually a reason for needing this to
happen....
Thanks for any clues.
--
Mark Tangard, Microsoft Word MVP
"Life is nothing if you're not obsessed." --John Waters
Sub DP_ZapInactiveSoftHyphens()
If Documents.Count = 0 Then Exit Sub
Dim i As Long, r As Range, r1 As Range, r2 As Range
Set r = Selection.Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^-"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWildcards = False
Do While .Execute
Set r = Selection.Range
r.MoveEnd wdCharacter, 1
Set r1 = ActiveDocument.Range(r.Start, r.Start)
Set r2 = ActiveDocument.Range(r.End, r.End)
r.MoveEnd wdCharacter, -1
If r1.Information(wdVerticalPositionRelativeToPage) _
= r2.Information(wdVerticalPositionRelativeToPage) Then
r.Characters(1).Delete
End If
Set r1 = Nothing
Set r2 = Nothing
Loop
End With
MsgBox "Done."
End Sub
a document that aren't being "used" (that is, aren't at a line break
doing their job). It compares the vertical position of each found
hyphen with the vertical position of the character following it and
deletes the hyphen if those 2 positions are different.
It works in a small file (a page or so), and it works in a large file if
run step by step from the VBE (which of course, is too slow to provide
any benefit.). It *doesn't* work if run from the document window on a
document of any appreciable size. In that case, *all* the soft hyphens
are removed.
I've tried this code with ^31 (ascii for soft hyphen) where "^-" is
shown below (for .Text), and have tried it with and without codes
displayed. No change in either case. Any ideas?
BTW, I haven't gone batty, there's actually a reason for needing this to
happen....
Thanks for any clues.
--
Mark Tangard, Microsoft Word MVP
"Life is nothing if you're not obsessed." --John Waters
Sub DP_ZapInactiveSoftHyphens()
If Documents.Count = 0 Then Exit Sub
Dim i As Long, r As Range, r1 As Range, r2 As Range
Set r = Selection.Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^-"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWildcards = False
Do While .Execute
Set r = Selection.Range
r.MoveEnd wdCharacter, 1
Set r1 = ActiveDocument.Range(r.Start, r.Start)
Set r2 = ActiveDocument.Range(r.End, r.End)
r.MoveEnd wdCharacter, -1
If r1.Information(wdVerticalPositionRelativeToPage) _
= r2.Information(wdVerticalPositionRelativeToPage) Then
r.Characters(1).Delete
End If
Set r1 = Nothing
Set r2 = Nothing
Loop
End With
MsgBox "Done."
End Sub