简体   繁体   English

解决VBA中的Web浏览器ActiveX控件失败(Excel 2013)

[英]Addressing a web browser ActiveX control fails in VBA (Excel 2013)

I'm having trouble with a piece of code I wrote a while ago for Excel 2007. I'm now using Excel 2013 and it's throwing a 438 runtime error. 我之前为Excel 2007编写的一段代码遇到了麻烦。我现在正在使用Excel 2013,它会抛出438运行时错误。

Here's the line that throwing the error. 这是引发错误的行。

 ActiveSheet.WebBrowser1.Visible = True

I've checked in design mode that the web browser object definitely exists in the active sheet and is called 'WebBrowser1'. 我已经在设计模式下检查了Web浏览器对象是否确实存在于活动工作表中,并称为“ WebBrowser1”。 I've also checked that MS Internet Controls is enabled. 我还检查了MS Internet Controls是否已启用。 Have MS changed the way the WebBrowser object works? MS是否更改了WebBrowser对象的工作方式?

I've found the problem and a workaround for my own machine but would really appreciate advice on a better way to handle this for distribution to other users. 我已经找到了自己的机器的问题和解决方法,但真的希望您能找到一种更好的方法来处理该问题并分发给其他用户。

The problem is that there is a KillBit set for the web browser object due to a security issue. 问题是由于安全问题,为Web浏览器对象设置了KillBit。

The workaround (which presumably leaves the user open to the security issue) is to go into the registry and change the value from 400 to 0. The address for my 64 bit system is: HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\15.0\\Common\\COM Compatibility\\{8856F961-340A-11D0-A96B-00C04FD705A2} but if you search for "COM Compatibility" you should find the right place. 解决方法(可能使用户容易遇到安全问题)是进入注册表并将值从400更改为0。我的64位系统的地址为: HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\15.0\\Common\\COM Compatibility\\{8856F961-340A-11D0-A96B-00C04FD705A2}但是如果您搜索“ COM兼容性”,则应该找到正确的位置。

After closing and restarting Excel the web browsers appeared and function as expected. 关闭并重新启动Excel后,将出现Web浏览器并按预期运行。

Lets say the ActiveSheet is Sheet1 Goto Object Browser > check for Class sheet1 under classes > Look for Members of Sheet1 ("WebBrowser1" should be there as a property) 可以说ActiveSheet是Sheet1 Goto对象浏览器>检查Class sheet1下的类Class sheet1 >查找Members of Sheet1 (“ WebBrowser1”应该作为属性存在)

Now Search for Class WebBrowser under Classes > Look for Members of WebBrowser (Check if Visible property is there. If yes (Sheet1.WebBrowser1.Visible = True) should work for you. 现在,在“类”>“查找Members of WebBrowser下搜索Class WebBrowser (检查是否存在Visible属性。如果是(Sheet1.WebBrowser1.Visible = True)适合您。

Else navigate through the property and identify which other property can be used to hide (you may guess it by name)) 否则,在属性中导航并确定可以用来隐藏其他属性(您可能会按名称猜测)

'this works in Excel 2013
Dim wb As WebBrowser: Set wb = Sheets("sheet1").Shapes("WebBrowser1").DrawingObject.Object
wb.Navigate url

I am guessing, as I cannot find any documentation to substantiate this, that in Excel2007 the default attribute of the Worksheet object must have been Shapes or a collection of objects on the sheet. 我正在猜测,因为找不到任何文档来证实这一点,因此在Excel2007中,工作表对象的默认属性必须为Shapes或工作表上的对象集合。 I too have noticed the ws.WebBrowser1 way of referencing the WebBrowser object instance on a sheet on the web, but in Excel2013 it does not work. 我也注意到ws.WebBrowser1引用Web表单上WebBrowser对象实例的方式,但是在Excel2013中它不起作用。 And Shapes is not Worksheets default attribute. 而且Shapes不是Worksheets的默认属性。 I'll keep looking... 我会继续寻找...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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