|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
守兄
小弟运行了您的程序
Sub getindex()
Dim opar As Paragraph
Dim myrange As Range
Dim nametext As String
Dim py As String
Application.ScreenUpdating = False
With ThisDocument
'遍历段落,将“py字头+汉字字头”自动标记索引项
For Each opar In .Paragraphs
Set myrange = opar.Range.Characters(1)
If nametext = "" Then
py = VBA.UCase(getpychar(myrange.Text))
.Indexes.MarkEntry Range:=myrange, entry:=py & ":" & myrange.Text, reading:=""
Else
'如果汉字字头myrange.Text不在nametext之中,则
If VBA.InStr(nametext, myrange.Text) = 0 Then
py = VBA.UCase(getpychar(myrange.Text))
.Indexes.MarkEntry Range:=myrange, entry:=py & ":" & myrange.Text, reading:=""
End If
End If
'累加文本
nametext = nametext & myrange.Text
Next opar
'重新定义一个range对象为文档起始位置
Set myrange = .Range(0, 0)
'在起始位置插入索引
.Indexes.Add Range:=myrange, HeadingSeparator:=wdHeadingSeparatorNone, Type:=wdIndexIndent, RightAlignPageNumbers:=True, NumberOfColumns:=2, SortBy:=wdIndexSortBySyllable, IndexLanguage:=wdsimplifiedcinese
.Indexes(1).TabLeader = wdTabLeaderDots
End With
Application.ScreenUpdating = True
End Sub
然后每次新建word文档 就出现
新建文档
请问这该如何解决
|
|