虎兄,我临时做了一个,可能不是太爽,你先用一下,请多提意见。 '* +++++++++++++++++++++++++++++
'* Created By I Love You_Word!@ExcelHome 2005-2-23 11:41:30
'仅测试于System: Windows NT Word: 10.0 Language: 2052
'^The Code CopyIn [ThisDocument-ThisDocument]^'
'* -----------------------------'请在操作之前,使用插入/书签,选择指定书签进行定位(选定),或者
'直接选定需要保护的页面内容
Sub ProtectByBookMark()
Dim StartRange As Long, EndRange As Long, MyRange1 As Range, MyRange2 As Range
Dim Sec1 As Integer, Sec2 As Integer, I As Integer, ActEnd As Long, Pw As String
On Error GoTo ErrHandle '启动错误处理程序
With Selection
If .Type = wdSelectionIP Then Exit Sub '如果未选定则退出程序
StartRange = .Start '起点位置
ActEnd = ActiveDocument.Content.End '终止位置
EndRange = VBA.IIf(.End = ActEnd, ActEnd - 1, .End)
End With
With ActiveDocument
'定义两个相当于光标位置
Set MyRange1 = .Range(StartRange, StartRange)
Set MyRange2 = .Range(EndRange, EndRange)
'分别取得"光标"位置所在节号
Sec1 = MyRange1.Information(wdActiveEndSectionNumber)
Sec2 = MyRange2.Information(wdActiveEndSectionNumber)
'如果文档中已有部分节保护了,则需要解除文档密码
ErrAgain:
If .ProtectionType <> wdNoProtection Then
Pw = InputBox("请输入文档解除密码!", "解除文档保护")
.Unprotect Password:=Pw
Else
Pw = InputBox("请输入文档保护密码!", "保护文档窗体")
End If
For I = Sec1 To Sec2
.Sections(I).ProtectedForForms = True
Next
.Protect wdAllowOnlyFormFields, , Pw
End With
Exit Sub
ErrHandle:
GoTo ErrAgain
End Sub
'---------------------- |