View Single Post
 
Old 01-09-2016, 07:14 AM
gmaxey gmaxey is offline Windows 7 32bit Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,621
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Numbered Fish,

Something weird going on here (Paul help us out).

I opened and new document and entered:

1-{Qoute "1"}

When toggled the content looks like this:

1-1

I ran your macro and NOTHING happened!

Like you seem to want to prevent, I thought would have occurred. Here is some code that illustrates the weird behavior that seems to be due to the "-" (dash) in the .Find string:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
'For replacing hyphens in numerical ranges with an en dash
Dim oRNg As Word.Range
  Set oRNg = ActiveDocument.Range
  With oRNg.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    'Note using 1-{Quote "1"} toggled to display 1-1
    .Text = "[0-9]-[0-9]" 'Wasn't found
    .Text = "[0-9]" & Chr(45) & "[0-9]" 'Wasn't found
    .Text = "[0-9]-" 'Found
    'Remove "-" between displayed numbers
    .Text = "[0-9][0-9]" 'Found
    'Put dash back between numbers
    .Text = "[0-9]*[0-9]" 'Found
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchWildcards = True
    While .Execute
      If oRNg.Characters(2) = Chr(45) Then
        If oRNg.Fields.Count = 0 Then
          If oRNg.Characters(3).Font.Superscript = False Then
            oRNg.Characters(2).Text = Chr(150)
            oRNg.Collapse wdCollapseEnd
            oRNg.Find.Execute
          End If
        End If
      End If
    Wend
  End With
lbl_Exit:
  Exit Sub
End Sub
Paul, do you have any explanation?

Best Regards,
Greg Maxey
The problem with socialism is that you eventually run out of other peoples' money. ~Margaret Thatcher
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote