标签:false name cti move 根据 document doc 字符 select
操作方法,鼠标逐一点击标题行,执行本宏,自动将标题编号取出作为书签名称
Sub 宏1() ‘ ‘ 宏1 宏 ‘ ‘
Dim myRange As Word.Range
Dim num As String, content As String
Selection.HomeKey Unit:=wdLine
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Set myRange = Selection.Range
With myRange ‘把Range结束范围往前移一个字符,目的是为了不包括换行符
.MoveEnd Unit:=wdWord, Count:=-1
‘取出段落序号
num = Trim(.ListFormat.ListString)
‘取出Heading的内容
content = Trim(.Text) End With
If num <> "" Then
num = Replace(num, ".", "")
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="P" + num
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
End If
End Sub
标签:false name cti move 根据 document doc 字符 select
原文地址:https://www.cnblogs.com/mol1995/p/9694759.html