我用execl 2016设计了一个小程序,由于不能保护工作薄,需要与用户有一定的交互操作,所以希望在excel启动时就屏蔽掉“开发工具”选项卡或其下的“设计模式”变为灰色状态,找了很多网页,大多是一闪而过,“设计模式”均可正常使用,请高手出手相助。谢谢!!、
下面是我找到的几行代码,应该是目前网络上可见的最高水平:
Sub EnterExitDesignMode(bEnter As Boolean)
Dim cbrs As CommandBars
Const sMsoName As String = "DesignMode"
Application.OnTime Now + TimeSerial(0, 0, 1), "TIMER_TEST"
Set cbrs = Application.CommandBars
If Not cbrs Is Nothing Then
If cbrs.GetEnabledMso(sMsoName) Then
If bEnter <> cbrs.GetPressedMso(sMsoName) Then
cbrs.ExecuteMso sMsoName
Stop
End If
End If
End If
End Sub
Public Sub TIMER_TEST()
If ActiveSheet.Name = strSheetName Then
EnterExitDesignMode True
Else
End If
End Sub
---------------------------------------------------------------
CommandBars("Exit Design Mode").Controls(1).Execute 'Enter Design Mode
CommandBars("Exit Design Mode").Controls(1).Reset 'Exit Design Mode