Excel VBA create an embedded WebBrowser and use it

前端 未结 2 1847
猫巷女王i
猫巷女王i 2021-01-02 23:27

Hi I\'m trying to dynamically create a web browser inside a spreadsheet and then use it but the WebBrowser functions don’t seem to work

Here is how I create the WebB

2条回答
  •  忘掉有多难
    2021-01-03 00:02

    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
    " 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

提交回复
热议问题