Sub FS()
'
' FS Macro
' 宏在 2013-6-28 由 微软用户 创建
'
' 分数起始标志
Const SignBegin = "《"
' 分数结束标志
Const SignEnd = "》"
' 分数线标志
Const SignSplit = "、"
Dim sf As Boolean, s As String
sf = ActiveDocument.ActiveWindow.View.ShowFieldCodes
If sf = False Then ActiveDocument.ActiveWindow.View.ShowFieldCodes = True
Selection.Find.ClearFormatting
With Selection.Find
.Text = SignBegin & "(*)" & SignSplit & "(*)" & SignEnd
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
While Selection.Find.Found
With Selection
s = .Text
'If s Like "*[!0-9/]*" Then Exit Sub
If InStr(1, s, SignSplit) > 0 And UBound(Split(s, SignSplit)) = 1 Then
.Text = "EQ \f(" & Split(s, SignSplit)(0) & "," & Split(s, SignSplit)(1) & ")"
.Text = Replace(.Text, SignBegin, "")
.Text = Replace(.Text, SignEnd, "")
With .Fields.Add(.Range, wdFieldEmpty, , False)
.Code.Text = Trim(.Code.Text)
.ShowCodes = False
End With
End If
End With
Selection.Find.Execute
Wend
ActiveDocument.ActiveWindow.View.ShowFieldCodes = sf
End Sub