gpt4 book ai didi

Excel VBA 创建嵌入式 WebBrowser 并使用它

转载 作者:行者123 更新时间:2023-12-03 14:12:14 26 4
gpt4 key购买 nike

嗨,我正在尝试在电子表格中动态创建一个 Web 浏览器,然后使用它,但 WebBrowser 功能似乎不起作用

这是我创建 WebBrowser 的方法

Set 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")
While myWebBrowser.Object.ReadyState <> READYSTATE_COMPLETE
Application.Wait (Now + TimeValue("0:00:01"))
Wend
myWebBrowser.Object.Refresh

更新2(几乎在那里):

现在我需要一种方法来删除 Sheet2.激活 Sheet1.激活
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"

更完整的例子:
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 并使用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19600586/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com