【问题标题】:Getting or Setting Internet Explorer Options with VBA使用 VBA 获取或设置 Internet Explorer 选项
【发布时间】:2013-12-17 19:04:09
【问题描述】:

我正在使用调用 Internet Explorer 的 Excel 工作簿并将工作簿用户定向到登录页面,以便对其进行验证,然后从我们的服务器检索数据。我发现如果用户在 IE 中启用了“保护模式”(Internet 选项 --> 安全),他们通常会在输入用户名和密码后“卡住”在登录页面上。禁用“保护模式”时,没有问题。

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

Dim objBrowser As InternetExplorer
Dim vProtected As Variant

Set objBrowser = New InternetExplorer

'Opens IE and navigates to log-in page
'The code here works as expected 

'No idea what to put in for arguments in GetProperty
vProtected = objBrowser.GetProperty("?")

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

InternetExplorer 对象的 GetProperty 方法上的 MSDN article 没有多大帮助。

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

感谢您的时间和考虑!

【问题讨论】:

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

标签: internet-explorer vba excel


【解决方案1】:

解决方案最终与我的目标大相径庭。我已经接受了这样一个事实,即我必须使用注册表才能实现我想要的行为。虽然这是不可取的,但这就是我最终在 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

【讨论】:

    【解决方案2】:

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

    您可能想要探索here 描述的保护模式 API,或here 描述的 URL 安全区域 API。

    【讨论】:

      猜你喜欢
      • 2017-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多