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 |
|
Sergey Grischenko
Add-in Express team
Posts: 7233
Joined: 2004-07-05
|
|