Excel VBA创建嵌入式WebBrowser并使用它 [英] Excel VBA create an embededed WebBrowser and use it
本文介绍了Excel VBA创建嵌入式WebBrowser并使用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我如何创建WebBrowser
设置myWebBrowser = Sheets(test)。OLEObjects.Add(ClassType:=Shell.Explorer.2 ,Link:= False,DisplayAsIcon:= False,left:= 147,top:= 60.75,width:= 141,height:= 96)
这将工作
myWebBrowser.top = 10
但这会给我一个错误
myWebBrowser.Navigate(about:blank)
有什么想法我应该怎么谢谢你
更新:
这也将无效,并发出错误:
myWebBrowser.Object.Document.body.Scroll =no
myWebBrowser.Object.Silent = True
myWebBrowser.Object .Navigate(about:blank)
虽然myWebBrowser.Object.ReadyState<> READYSTATE_COMPLETE
Application.Wait(Now + TimeValue(0:00:01))
Wend
myWebBrowser.Object.Refresh
更新2(几乎有):
现在我需要一种方法来删除 Sheet2。激活Sheet1.Activate
Sheet2.Activate
Sheet1.Activate
设置wb = myWebBrowser.Object
带有wb
.Silent = True
。导航about:blank
Do While .ReadyState<> READYSTATE_COMPLETE
Application.Wait(Now + TimeValue(0:00:01))
循环
.Document.Opentext / html
Do While .ReadyState< > READYSTATE_COMPLETE
Application.Wait(Now + TimeValue(0:00:01))
循环
.Document.write html
.Document.Close
.Document .body.Scroll =no
.Refresh
Debug.Print .Document.body.innerHTML
结束
解决方案
myWebBrowser.Object.Navigatehttp://www.google.com
更完整的例子:
Sub AddWebBroswerToWorksheet()
Dim myWebBrowser
Dim wb,doc,x As Long
Sheet2.Activate
Sheet1.OLEObjects(1 ).Delete
设置myWebBrowser = Sheet1.OLEObjects.Add(ClassType:=Shell.Explorer.2,_
左:= 147,顶部:= 60.75,宽度:= 400 ,高度:= 400)
设置wb = myWebBrowser.Object
带有wb
.Navigateabout:blank
.Document.Opentext / html
对于x = 1到100
.Document.wri tehello world< br>
下一个x
.Document.Close
.Document.body.Scroll =否
Debug.Print .Document.body.innerHTML
结束
Sheet1.Activate'切换回到页面似乎
''触发对象的显示
End Sub
Hi I'm trying to dynamically create a web browser inside a spreadsheat and then use it but the WebBrowsers functions don’t seem to work
Here is how I create the WebBrowser
Set myWebBrowser = Sheets("test").OLEObjects.Add(ClassType:="Shell.Explorer.2", Link:=False, DisplayAsIcon:=False, left:=147, top:=60.75, width:=141, height:=96)
This will work
myWebBrowser.top = 10
But this will give me an error
myWebBrowser.Navigate ("about:blank")
Any ideas on what should I do thank you
UPDATE:
This will also don't work and give an error:
myWebBrowser.Object.Document.body.Scroll = "no"
myWebBrowser.Object.Silent = True
myWebBrowser.Object.Navigate ("about:blank")
While myWebBrowser.Object.ReadyState <> READYSTATE_COMPLETE
Application.Wait (Now + TimeValue("0:00:01"))
Wend
myWebBrowser.Object.Refresh
UPDATE 2 (almost there):
Now I need a way to remove the Sheet2.Activate Sheet1.Activate
Sheet2.Activate
Sheet1.Activate
Set wb = myWebBrowser.Object
With wb
.Silent = True
.Navigate "about:blank"
Do While .ReadyState <> READYSTATE_COMPLETE
Application.Wait (Now + TimeValue("0:00:01"))
Loop
.Document.Open "text/html"
Do While .ReadyState <> READYSTATE_COMPLETE
Application.Wait (Now + TimeValue("0:00:01"))
Loop
.Document.write html
.Document.Close
.Document.body.Scroll = "no"
.Refresh
Debug.Print .Document.body.innerHTML
End With
解决方案
myWebBrowser.Object.Navigate "http://www.google.com"
more complete example:
Sub AddWebBroswerToWorksheet()
Dim myWebBrowser
Dim wb, doc, x As Long
Sheet2.Activate
Sheet1.OLEObjects(1).Delete
Set myWebBrowser = Sheet1.OLEObjects.Add(ClassType:="Shell.Explorer.2", _
Left:=147, Top:=60.75, Width:=400, Height:=400)
Set wb = myWebBrowser.Object
With wb
.Navigate "about:blank"
.Document.Open "text/html"
For x = 1 To 100
.Document.write "hello world<br>"
Next x
.Document.Close
.Document.body.Scroll = "no"
Debug.Print .Document.body.innerHTML
End With
Sheet1.Activate 'switching back to the sheet seems to
' ' trigger the display of the object
End Sub
这篇关于Excel VBA创建嵌入式WebBrowser并使用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文