以下是引用sylun在2007-1-29 23:28:43的发言:参照老大关于进行批量转脚注的VBA代码改了一个标记索引项的代码,测试过可以标记,但标记在书名的前面而不是后面,不知如何修改,也不懂怎样写插入索引的代码。 Sub Example() Dim myRange As Range, NtRange As Range, strNT As String Application.ScreenUpdating = False Set myRange = ActiveDocument.Content NF: With myRange.Find .ClearFormatting .Text = "《*》" .MatchWildcards = True Do While .Execute = True Set NtRange = ActiveDocument.Range(myRange.Start, myRange.Start) strNT = myRange.Text ActiveDocument.Fields.Add Range:=NtRange, Type:=wdFieldEmpty, _ Text:="xe " & Chr(34) & strNT & Chr(34), _ PreserveFormatting:=False myRange.SetRange myRange.End, ActiveDocument.Content.End - 1 GoTo NF Loop End With Application.ScreenUpdating = True End Sub 另,想请教C版主的索引项中的拼音首字母是用什么方法加上去的。 呵呵,sylun兄,我做了一个示范吧,你看一下,也供楼主直接应用: '* +++++++++++++++++++++++++++++ '* Created By SHOUROU@ExcelHome 2007-1-30 6:13:37 '仅测试于System: Windows NT Word: 11.0 Language: 2052 '№ 0148^The Code CopyIn [ThisDocument-ThisDocument]^' '* ----------------------------- Option Explicit
Sub Example() Dim myRange As Range, myString As String, myField As Field, lngField As Integer Application.ScreenUpdating = False Set myRange = ActiveDocument.Content NF: With myRange.Find .ClearFormatting .MatchWildcards = True .Text = "《*》" Do While .Execute myString = myRange.Text myRange.SetRange myRange.End, myRange.End Set myField = ActiveDocument.Indexes.MarkEntry(Range:=myRange, Entry:=myString, EntryAutoText:=myString) lngField = Len(myField.Code.Text) + 2 myRange.SetRange myRange.End + lngField, ActiveDocument.Content.End - 1 GoTo NF Loop End With Application.ScreenUpdating = True End Sub '----------------------
|