如何确定Windows 10上是否禁用了VBA ActiveX?

时间:2019-09-19 13:05:47

标签: excel vba windows activex

我已经为UserForm编写了Excel VBA,该用户窗体具有一个调用CommonDialog.ShowColor的按钮。

在我的开发人员系统上,没有问题,在网络系统上,出于安全考虑,ActiveX被禁用。

在初次加载Excel工作簿时,我可以忍受错误警告,我要避免的是当用户单击按钮以显示“颜色对话框”时出现VBA编辑器。

我已经在button_click事件中尝试了“出错时转到”,但这不起作用。

是否可以从VBA中测试是否禁用ActiveX,然后再禁用按钮?

谢谢

1 个答案:

答案 0 :(得分:0)

如果您的系统管理员正在应用组策略,请尝试此操作:

Private Sub AX_Click()
    On Error GoTo ErrorHandler
    Dim WS As Object, RegistryKey As String, RegistryKeyValue As String
    Set WS = CreateObject("WScript.Shell")
    RegistryKey = _
"HKEY_CURRENT_USER\Software\Policies\Microsoft\Office\Common\Security\DisableAllActiveX"
    If RegistryKey = "" Then Exit Sub
    If WS.RegRead(RegistryKey) = 0 Then
        MsgBox "Disabled"
    Else
        MsgBox "Enabled "
    End If
    Exit Sub
ErrorHandler:
    MsgBox "Key does not exist."
End Sub

或者如果他使用不同的方法更改注册表项,例如:trusted filestrusted locations