简体   繁体   中英

How Do I Tell If VBA ActiveX is disabled on Windows 10?

I have written an Excel VBA for a UserForm that has a button that calls CommonDialog.ShowColor.

On my developer system there are no issues, on our networked systems ActiveX is disabled due to security concerns.

I can live with the error warnings on initial loading of the Excel Workbook, what I want to avoid is having the VBA Editor come up when a user clicks the button to show the Color Dialog.

I've tried On Error Goto within the button_click event but that does not work.

Is there a way to test, from within VBA, if ActiveX is disabled and then disable the button?

Thanks

Try this if your system administrator is applying group policy:

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

Or change the registry key if he uses a different method, like: trusted files or trusted locations .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM