如何从右向左移动减号?

How To Move Minus Sign From Right To Left?

我需要一个 MSWord 宏来转换以下这些值:

568.63- 682.3- 12.78-

-568.63 -682.3 -12.78

您实际上不需要为此使用宏。您只需要一个通配符 Find/Replace 即可:

Find = (<[0-9.]@)(-)
Replace = 

作为一个宏,这将变成:

Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "(<[0-9.]@)(-)"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
  End With
End With
Application.ScreenUpdating = True
End Sub

至于@Freeflow 发现的 80.9-100.1 问题,我倾向于将这些连字符替换为普通连字符以外的其他内容(例如,不间断的连字符)。在这种情况下,您可以使用编码如下的宏:

Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchWildcards = True
    .Text = "([0-9])-([0-9])"
    .Replacement.Text = "^~"
    .Execute Replace:=wdReplaceAll
    .Text = "(<[0-9.]@)(-)"
    .Replacement.Text = ""
    .Execute Replace:=wdReplaceAll
  End With
End With
Application.ScreenUpdating = True
End Sub