请参考: '* +++++++++++++++++++++++++++++
'* Created By I Love You_Word!@ExcelHome 2005-6-3 4:56:49
'仅测试于System: Windows NT Word: 10.0 Language: 2052
'^The Code CopyIn [ThisDocument-ThisDocument]^'
'* -----------------------------Option Explicit
Sub Exapmle()
On Error Resume Next
Application.CustomizationContext = ActiveDocument
With Application.CommandBars
'看指定条件,文档变量1的数值
If ThisDocument.Variables("Test").Value <> 1 Then
'禁用常用工具栏的打印命令
.Item("Standard").Controls("打印(&P)").Enabled = False
'禁用文件打印命令
.Item("File").Controls("打印(&P)...").Enabled = False
'禁用快捷键(CTRL+P)命令
FindKey(KeyCode:=BuildKeyCode(wdKeyControl, wdKeyP)).Disable
Else
'恢复打印命令
' .Item("Standard").Controls("打印(&P)").Reset
' .Item("File").Controls("打印(&P)...").Reset
.Item("Standard").Controls("打印(&P)").Enabled = True
'禁用文件打印命令
.Item("File").Controls("打印(&P)...").Enabled = True
'重新指定快捷键命令
FindKey(KeyCode:=BuildKeyCode(wdKeyControl, wdKeyP)).Rebind _
KeyCategory:=wdKeyCategoryCommand, Command:="FilePrint"
End If
End With
End Sub
'----------------------
Sub Sample() '定义一个文档变量并指定其值
ThisDocument.Variables.Add Name:="Test", Value:=1
End Sub
'----------------------
Sub Easy()
ThisDocument.Variables("Test").Value = 1
End Sub
'----------------------相关链接:http://club.excelhome.net/dispbb ... id=98653&skin=0 如果你要分开指定禁用和恢复,我不写了,请楼主拆分一下即可. |