vba ActiveX Microsoft Web 浏览器对象(将网页嵌入到 excel 文件中)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28042791/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ActiveX Microsoft Web Browser Object (embedding web page into excel file)
提问by Qbik
I try to embed web page into .xlsm Excel 2010 file. That what I have made so far :
In Sheet1 I've inserted ActiveX control called 'Microsoft Web Browser' its default name is WebBrowser1 (Developer->Insert->More Controls->Microsoft Web Browser). Then using VBA editor I placed following code into sheet module Sheet1 :
我尝试将网页嵌入到 .xlsm Excel 2010 文件中。到目前为止我所做的:
在 Sheet1 中,我插入了名为“Microsoft Web Browser”的 ActiveX 控件,它的默认名称是 WebBrowser1(开发人员->插入->更多控件->Microsoft Web 浏览器)。然后使用 VBA 编辑器将以下代码放入工作表模块 Sheet1 中:
Private Sub Worksheet_Activate()
WebBrowser1.Navigate "http://stackoverflow.com/"
End Sub
I've tried various websites and html files placed on my local hard drive but the content displayed in WebBrowser1 control is always the same - 'Internet Explorer Cannot Display The Webpage' error with no error from Excel VBA alone. It seems that Microsoft Web Browser Object can't establish connection to web page.
我尝试了放置在本地硬盘驱动器上的各种网站和 html 文件,但 WebBrowser1 控件中显示的内容始终相同 - “Internet Explorer 无法显示网页”错误,仅来自 Excel VBA 没有错误。Microsoft Web Browser Object 似乎无法建立与网页的连接。
回答by Leonardo Atalla
try this:
尝试这个:
'declare the web browser object for future reference and / or for listening to its events
Dim WithEvents ie As WebBrowser
'navigate when the worksheet is activated.
Private Sub Worksheet_Activate()
Set ie = ActiveSheet.WebBrowser1
ie.Navigate2 "http://stackoverflow.com/"
End Sub
回答by Niki Kotsou
After Navigate you have to put parenthesis maybe that's why it cannot read the site. It should be like
在 Navigate 之后,您必须加上括号,这可能就是它无法读取该站点的原因。它应该像
WebBrowser1.Navigate("http://www.stackoverflow.com")