以下是引用lhdcxz在2006-11-18 15:03:19的发言:我准备设置为书签的名单太多,怎样才能用代码一次性地完成呢? '* +++++++++++++++++++++++++++++ '* Created By SHOUROU@ExcelHome 2006-11-18 19:23:07 '仅测试于System: Windows NT Word: 11.0 Language: 2052 '№ 0099^The Code CopyIn [ThisDocument-ThisDocument]^' '* ----------------------------- Option Explicit
Sub Example() Dim BkRange As Range, oPar As Paragraph, bkName As String '对选定文本按段落进行书签添加 On Error Resume Next With Selection If .Type = wdSelectionIP Or .Type <> wdSelectionNormal Then Exit Sub Set BkRange = .Range For Each oPar In BkRange.Paragraphs bkName = VBA.Replace(oPar.Range.Text, Chr(13), "") bkName = VBA.Replace(bkName, " ", "") If bkName = "" Then Else With ActiveDocument If .Bookmarks.Exists(bkName) = True Then MsgBox "请注意,该书签名(" & bkName & ")已存在!", vbInformation .Bookmarks.Add Name:=bkName, Range:=oPar.Range End With End If Next End With End Sub '----------------------
|