Internet explorer 使用VBA获取或设置Internet Explorer选项

Internet explorer 使用VBA获取或设置Internet Explorer选项,internet-explorer,vba,excel,Internet Explorer,Vba,Excel,我在一个Excel工作簿中工作,该工作簿调用internet explorer并将工作簿用户引导到登录页面,以便验证它们,然后从服务器检索数据。我发现,如果用户在IE中启用了“受保护模式”(Internet选项-->安全),那么在输入用户名和密码后,他们通常会在登录页面上“卡住”。禁用“保护模式”时,不存在任何问题 我正在尝试创建一个宏,该宏将检测他们的IE设置,并在启用保护模式时通知用户(如果可能,还可能使用PutProperty方法使用VBA为他们更改此设置)。我目前正在使用Microsof

我在一个Excel工作簿中工作,该工作簿调用internet explorer并将工作簿用户引导到登录页面,以便验证它们,然后从服务器检索数据。我发现,如果用户在IE中启用了“受保护模式”(Internet选项-->安全),那么在输入用户名和密码后,他们通常会在登录页面上“卡住”。禁用“保护模式”时,不存在任何问题

我正在尝试创建一个宏,该宏将检测他们的IE设置,并在启用保护模式时通知用户(如果可能,还可能使用
PutProperty
方法使用VBA为他们更改此设置)。我目前正在使用Microsoft Internet控件参考。我尝试的路径如下(当然是在一个子例程中)

我不确定实际返回的是什么数据类型
GetProperty
(因此是变量),我不知道为参数传递什么。此外,如果这是一种完全错误的做法,我愿意采取新的行动

InternetExplorer对象的GetProperty方法上的错误没有什么帮助

值得一提的是,我对Microsoft Internet控件和InternetExplorer对象还很陌生,这是我第一次使用它


感谢您的时间和考虑

我认为您不能使用GetProperty读取浏览器的安全设置。从文档:

  • :获取与用户定义的属性名关联的值
  • :将用户定义的名称/值对与对象关联

您可能希望探索所描述的受保护模式API,或者所描述的URL安全区域API。

最终解决方案与我所要的大不相同。我已经接受了这样一个事实:为了达到我想要的行为,我必须使用注册表。虽然这是不可取的,但以下是我最终在VBA中所做的

这不是我的最终代码,因为我仍在项目中工作,但它已经足够了

Dim obj_Shell
Dim v_Result As Variant

'Variable to capture user response
Dim v_Response As Variant

Set obj_Shell = CreateObject("WScript.Shell")

'CHECK INTERNET EXPLORER PROTECTED MODE SETTINGS

'Reads the registry key that determines whether 'Protected Mode' is enabled in internet explorer for the 'Internet' security zone
'as opposed to 'Local intranet' or 'Trusted Sites', etc.
'The 3 in the registry key path refers to the zone 'Internet'.

Debug.Print "Checking user's Internet Explorer protected mode settings..."

v_Result = obj_Shell.RegRead _
("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3\2500")

Select Case v_Result
    Case 0 'Protected Mode is enabled
        Debug.Print "   Protected mode is enabled!"
        v_Response = MsgBox("Protected mode is enabled in Internet Explorer.  " & _
        "This may cause issues with your submission.  " & _
        "Would you like to disable protected mode?", vbYesNo, "Protected Mode Enabled")

        If v_Response = vbYes Then
            obj_Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3\2500", 3, "REG_DWORD"
            MsgBox ("Protected mode has been disabled!  Submission will not proceed.")
        End If

    Case 3 'Protected Mode is disabled
        Debug.Print "   Protected mode is disabled"
    Case Else
        Debug.Print "Unable to determine status of protected mode in IE"
        Debug.Print v_Result
End Select

作为一种解决方法,您可以将该网站添加到IE中的受信任网站列表中。我认为这将禁用该网站的受保护模式。我认为,为了做到这一点,我必须修改用户的注册表,这实际上不是一个可行的选项。考虑到我的限制,我也愿意接受这是一项不可能完成的任务,只是想得到专家的建议。
Dim obj_Shell
Dim v_Result As Variant

'Variable to capture user response
Dim v_Response As Variant

Set obj_Shell = CreateObject("WScript.Shell")

'CHECK INTERNET EXPLORER PROTECTED MODE SETTINGS

'Reads the registry key that determines whether 'Protected Mode' is enabled in internet explorer for the 'Internet' security zone
'as opposed to 'Local intranet' or 'Trusted Sites', etc.
'The 3 in the registry key path refers to the zone 'Internet'.

Debug.Print "Checking user's Internet Explorer protected mode settings..."

v_Result = obj_Shell.RegRead _
("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3\2500")

Select Case v_Result
    Case 0 'Protected Mode is enabled
        Debug.Print "   Protected mode is enabled!"
        v_Response = MsgBox("Protected mode is enabled in Internet Explorer.  " & _
        "This may cause issues with your submission.  " & _
        "Would you like to disable protected mode?", vbYesNo, "Protected Mode Enabled")

        If v_Response = vbYes Then
            obj_Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3\2500", 3, "REG_DWORD"
            MsgBox ("Protected mode has been disabled!  Submission will not proceed.")
        End If

    Case 3 'Protected Mode is disabled
        Debug.Print "   Protected mode is disabled"
    Case Else
        Debug.Print "Unable to determine status of protected mode in IE"
        Debug.Print v_Result
End Select