|
* 楼主,最大序号我已改为 9999,如果嫌小,继续增加 9 即可(其实序号不必限制,按一次出一个,按着不放即可连续出)。
* 请将前两天的宏全部删除(包括 3 个小宏),换上今天的宏(热键我已经改了)。
- Sub AutoOpen()
- If ActiveDocument.FullName Like "*.txt" Then MsgBox "本文档为纯文本!", 0 + 16
- CustomizationContext = NormalTemplate
- KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyF3), KeyCategory:=wdKeyCategoryMacro, Command:="插入正文序号"
- KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyF4), KeyCategory:=wdKeyCategoryMacro, Command:="插入脚注序号"
- KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyF5), KeyCategory:=wdKeyCategoryMacro, Command:="另存为纯文本"
- MsgBox "F3:插入正文序号 F4:插入脚注序号 F5:另存为纯文本", 0 + 48, "请按下列热键执行宏!"
- End Sub
- Sub 另存为纯文本()
- With ActiveDocument
- .SaveAs FileName:=Left(.FullName, Len(.FullName) - 4) & "_TXT" & ".txt", FileFormat:=wdFormatText
- End With
- MsgBox "本文档(纯文本)已保存!", 0 + 48
- End Sub
- Sub 插入正文序号()
- Dim r As Range, n&, m$, i&, x&, y&, oldName$, NewName$
- With Selection
- If Not .Type = wdSelectionIP Then .MoveLeft
- Set r = .Range
- End With
- With ActiveDocument.Content.Find
- .ClearFormatting
- .Text = ",," & "[0-9]{1,2}" '中文全角逗号
- .Forward = True
- .MatchWildcards = True
- Do While .Execute
- With .Parent
- .Font.Color = wdColorRed '红色(本行代码可以删除/注释)
- If Len(.Text) = 3 Then x = Right(.Text, 1) Else x = Right(.Text, 2)
- If y < x Then y = x
- .Start = .End
- i = 1
- End With
- Loop
- If i = 1 Then .Parent.Select Else GoTo sk
- With Selection
- Do
- .MoveStart 1, -1
- Loop Until .Text Like ",,*"
- If Len(.Text) = 4 Then n = Right(.Text, 2) Else n = Right(.Text, 1)
- End With
- End With
- r.Select
- sk:
- If y = 9 Then Exit Sub '最大序号
- m = y + 1
- With Selection
- .TypeText Text:=",," & m
- If Len(m) = 1 Then
- .MoveStart 1, -3
- Else
- .MoveStart 1, -4
- End If
- .Font.Color = wdColorRed '红色(本行代码可以删除/注释)
- .MoveRight
- End With
- End Sub
- Sub 插入脚注序号()
- Dim n&, x&, y&
- '查找正文最大序号
- With ActiveDocument.Content.Find
- .ClearFormatting
- .Text = ",," & "[0-9]{1,2}"
- .Forward = True
- .MatchWildcards = True
- Do While .Execute
- With .Parent
- If Len(.Text) = 3 Then x = Right(.Text, 1) Else x = Right(.Text, 2)
- If y < x Then y = x
- .Start = .End
- End With
- Loop
- End With
- If y = 0 Then MsgBox "正文无序号!", 0 + 16: Exit Sub
- '文尾插入脚注序号
- With Selection
- .EndKey Unit:=wdStory
- .TypeParagraph
- Do
- n = n + 1
- .Font.Color = wdColorPink '粉色(本行代码可删除/注释)
- .TypeText Text:=",," & n & "." & vbCr
- Loop Until n = y
- .HomeKey Unit:=wdStory
- End With
- ActiveDocument.Paragraphs.Last.Range.Delete
- End Sub
复制代码 |
|