|
发表于 2002-10-25 17:15:00
|
显示全部楼层
函数如下:
'锁定菜单项
Public Sub ClockMenu(ByVal Name As String, ByVal bEnable As Boolean)
Dim PMenuObj As AcadPopupMenu
Dim EntObj As AcadPopupMenuItem
Dim s As String
On Error GoTo ErrTrap
If Name = "" Then Exit Sub
If InStr(Name, "...") 0 Then '"..."及之后的内容不考虑
Name = Left(Name, InStr(Name, "...") - 1)
End If
If InStr(Name, "Ctrl") Then '快捷键不考虑
Name = Left(Name, InStr(Name, "Ctrl") - 1)
End If
Name = Trim(Name)
For Each PMenuObj In Application.MenuBar
For Each EntObj In PMenuObj
s = EntObj.Caption
If InStr(s, "...") 0 Then
s = Left(s, InStr(s, "...") - 1)
End If
If InStr(s, "Ctrl") Then
s = Left(s, InStr(s, "Ctrl") - 1)
End If
s = Trim(s)
If StrComp(s, Name, vbTextCompare) = 0 Then
EntObj.Enable = bEnable
Exit For
End If
Next
Next
Set EntObj = Nothing
Set PMenuObj = nohting
Exit Sub
ErrTrap:
If Not (EntObj Is Nothing) Then Set EntObj = Nothing
If Not (PMenuObj Is Nothing) Then Set PMenuObj = nohting
On Error GoTo 0
End Sub
使用方法:
Sub Main()
ClockMenu "新建(&N)", False
End Sub |
|