webbrowser control inside Excel Worksheet

Add-in Express™ Support Service
That's what is more important than anything else

webbrowser control inside Excel Worksheet
how to make the webbrowser control works well in worksheet with vb.net 
Forrest




Posts: 10
Joined: 2016-09-11
I'm trying to work with webbrowser in Excel.
When I drop a webbrowser control in the worksheet, and write some VBA code, it works well.

such as:

Private Sub CommandButton1_Click()
WebBrowser1.Navigate ("C:\DataMap\map.html")
End Sub

But when I turned to VS and Add-in Express, it didn't work.

Dim sheet As Excel.Worksheet = DirectCast(ExcelApp.ActiveSheet, Excel.Worksheet)
Dim web As Object
web = sheet.OLEObjects.Add(ClassType:="Shell.Explorer.2", Link:=False, DisplayAsIcon:=False, Left:=303.75, Top:=52.5, Width:=317.25, Height:=167.25)
web.Navigate("http://google.com")

error info: the object can't use the method of 'Navigate'.

then I tried:

Dim sheet As Excel.Worksheet = DirectCast(ExcelApp.ActiveSheet, Excel.Worksheet)
Dim web As webbrowser
web = sheet.OLEObjects.Add(ClassType:="Shell.Explorer.2", Link:=False, DisplayAsIcon:=False, Left:=303.75, Top:=52.5, Width:=317.25, Height:=167.25)
web.Navigate("http://google.com")

error info: can't cast the object of 'System.__ComObject' to System.Windows.Forms.WebBrowser.


I wanna know how to correct the code to make the webbrowser work well.
enjoy life
Posted 07 Mar, 2017 04:26:39 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hello,

The 'Add' method of the OLEObjects object returns an instance of OLEObject. To access the browser you need to use the 'Object' property of the OLEObject object:
https://msdn.microsoft.com/en-us/library/office/ff840968.aspx
https://msdn.microsoft.com/en-us/library/office/ff840244.aspx
Posted 07 Mar, 2017 09:31:48 Top