使用VBA获取或设置Internet Explorer选项 [英] Getting or Setting Internet Explorer Options with VBA

查看:553
本文介绍了使用VBA获取或设置Internet Explorer选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am working within an Excel workbook that calls internet explorer and directs the workbook user to a log-in page in order to validate them and then retrieve data from our server. I have found that if users have 'Protected Mode' (Internet Options --> Security) enabled in IE they will often get "stuck" on the log-in page after entering their username and password. When 'Protected Mode' is disabled, there is no issue.

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

I am trying to create a macro that will detect their IE settings and notify the user if protected mode is enabled (and potentially change this setting for them with VBA using the PutProperty method, if possible). I am currently working with Microsoft Internet Controls reference. The route I have attempted is below (within a subroutine, of course).

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实际返回(因此是变体),而且我不知道将其作为参数传递给什么.此外,如果这完全是错误的方法,那么我可以采取新的行动方案.

I am unsure of what data type GetProperty actually returns (hence the variant) and I do not know what to pass in it for arguments. Additionally, if this is the wrong way entirely to do this I am open to a new course of action.

MSDN文章 InternetExplorer对象的GetProperty方法没有帮助.

The MSDN article on the GetProperty method of the InternetExplorer object was less than helpful.

值得一提的是,我是Microsoft Internet Controls和InternetExplorer对象的新手,这是我第一次使用它.

It is worth mentioning I am quite new to Microsoft Internet Controls and the InternetExplorer object, this is the first time I've worked with it.

谢谢您的时间和考虑!

推荐答案

该解决方案最终与我想要的解决方案大不相同.我已经辞职了,我必须与注册表一起玩才能实现我想要的行为.尽管这是不希望的,但这是我最终在VBA中所做的.

The solution ended up being vastly different than what I was going for. I have resigned myself to the fact that I must play with the registry in order to achieve the behavior I want. Though this was undesirable, here is what I ended up doing in VBA.

这不是我的最终代码,因为我仍在从事该项目,但这已足够.

This is not my final code, as I am still working on the project, but it suffices.

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

这篇关于使用VBA获取或设置Internet Explorer选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆