Link to home
Start Free TrialLog in
Avatar of lep1
lep1

asked on

VB.NET: Can't load Excel (.xlsx) into WebBrowser on Windows Form

I have all the references specified for using Excel and WebBrowser (Internet Tools .COM, etc.) and also use the following imports:

Imports Microsoft.Office.Core
Imports Excel = Microsoft.Office.Interop.Excel

Public oDocument As Object

However, after placing a WebBrowser1 on a Windows Form, calling on a file that is e.g. myfile.xlsx, and using the code below, the Webbrowser1 simply shows an info icon, and nothing happens.   Is there something I am missing?   (Note that the msgbox in the NavigateComplete2 never fires).

Also, how can I only show the column and row headers along with the sheet data, thus killing all the Excel menu commands and tools?   (I only want the user to see the gray-colored row and column headers along with the sheet data).  


Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
  
        Dim filename As String
    
        filename="c:\myfile.xlsx"

        Me.WebBrowser1.Navigate(filename)

End Sub

Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, URL As Object)
        MsgBox("NavigateComplete Event")
        On Error Resume Next
        oDocument = pDisp.Document
End Sub

Open in new window

Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

I assume the real file does actually exist in the path you specify.  
Check it - there are numbers of questions here where it doesn't when a path has been assumed.

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
 
        Dim filename As String
   
        filename="c:\myfile.xlsx"
MsgBox(filename)

        Me.WebBrowser1.Navigate(filename)

End Sub


Does the xlsx file actually open in excel when you double click on it from windows explorer ?
Avatar of lep1
lep1

ASKER

Yes, a VBA type of workbook opens with the data. I noticed on a forum that in VB.NET 2010 and newer Office ( I am using 2010 ), that Navigate won't open an Excel.  Rather an activeX control needs to be made.
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lep1

ASKER

Indeed, most forum posts regarding use of IE to open an Excel in webbrowser are 7-12 years old, and none address Office 2010 and Visual Studio >=2010
Avatar of lep1

ASKER

Interestingly the worst post claimed that not all your users would be able to open excel in webbrowser via ie due to variation in default sec settings. This is not good for excel and webbrowser