可试试如下程序:
Sub Marking() '运行本程序前请先对需编号标记的内容加下划线 Dim oRange As Range, myPar As Paragraph, myRange As Range, oh As Single, n As Byte Dim pl As Long, pt As Long, pw As Long, ph As Long, w As Single, h As Single, myShape As Shape Application.ScreenUpdating = False '如果没有选定区域则进行全文档处理 Set oRange = IIf(Selection.Type = wdSelectionIP, ActiveDocument.Content, Selection.Range) '编号规则暂定为段落不同重新编号 For Each myPar In oRange.Paragraphs Set myRange = myPar.Range oh = myRange.Characters(1).Information(wdVerticalPositionRelativeToTextBoundary) With myRange.Find .ClearFormatting .Format = True .Font.Underline = wdUnderlineSingle Do While .Execute n = n + 1 With myRange .Font.Underline = wdUnderlineNone .Fields.Add myRange, wdFieldEmpty, "eq \o(\x\bo(" & .Text & "))", False .MoveEnd .Fields(1).Code.Text = RTrim(.Fields(1).Code.Text) .Select ActiveWindow.GetPoint pl, pt, pw, ph, Selection.Range pl = PixelsToPoints(pl) pt = PixelsToPoints(pt) pw = PixelsToPoints(pw) ph = PixelsToPoints(ph) w = Selection.Information(wdHorizontalPositionRelativeToTextBoundary) h = Selection.Information(wdVerticalPositionRelativeToTextBoundary) Set myShape = Me.Shapes.AddTextbox(msoTextOrientationHorizontal, w, h - oh + .Font.Size + 2, pw, ph, myPar.Range) With myShape .Select .Height = .Height - .TextFrame.MarginTop - .TextFrame.MarginBottom .Width = .Width - .TextFrame.MarginLeft - .TextFrame.MarginRight .TextFrame.MarginTop = 0 .TextFrame.MarginBottom = 0 .TextFrame.MarginLeft = 0 .TextFrame.MarginRight = 0 .Line.Visible = msoFalse .Fill.Visible = msoFalse Selection.HomeKey Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter Fields.Add Selection.Range, wdFieldEmpty, "=" & n & " \*ALPHABETIC", False End With .SetRange .End, myPar.Range.End End With Loop End With n = 0 Next Application.ScreenUpdating = True End Sub
[此贴子已经被作者于2008-4-12 14:49:12编辑过] |