Home » Visual Studio

navigate to specific excel sheet with web browser control


In my visual studio project I have web browser control called WBbackupPreview.

I have following piece of code under a button:

WBbackupPreview.Navigate("c:\backupFiles\ReconBackup.xls") - it works but navigates to first worksheet in file.

File 'c:\backupFiles\ReconBackup.xls' has 3 worksheets: sheet1, sheet2, sheet3.

How to navigate  in web browser to 3rd worksheet, either by worksheet index or worksheet name ?



4 Answers Found


Answer 1

Hi szarcin,

In VSTO, such as excel  AddIn we usually use the code  below to locate to some sheet  in Workbook.
 Excel.Application myExcelApp = this.Application;
   Excel.Workbook mybook = myExcelApp.Workbooks.Open("C:\\Users\\Desktop\\Book1.xls",
missing,missing,missing,missing); Excel.Worksheet mysheet=mybook.Worksheets.get_Item(3) as Excel.Worksheet; mysheet.Activate();
When open the Excel, it will direct to sheet3 in the Workbook. However, I haven't tried that when combined to web  browser.
Since the webbrowser will show htmlDocument by default. I will try to make a program and inform you in details later.
Furthermore, here is a link about "How to use the WebBrowser control  to open Office documents in Visual C#2005 or in Visual C#.NET."
Hope it will be helpful. Any further questions or if I misunderstood you, please feel free to contact. Thank you!

Best Regards,
Amy Li
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

Answer 2

Hi szarcin,

I've made a program targeting VS2008 and Excel2003. And I find it seems no directly way to set the Excel sheet.
However, you can develop an Excel AddIn to the Excel and then when you run the program of WebBrowser, it will
locate to sheet3.
In the AddIn project, the code  is like that:

private void ThisAddIn_Startup(object sender, System.EventArgs e) 
Excel.Application thisExcelApp = this.Application; 
Excel.Workbook mybook = thisExcelApp.Workbooks.get_Item(1) as Excel.Workbook; 
Excel.Worksheet mysheet = mybook.Worksheets.get_Item(3) as Excel.Worksheet; 
Then in the Winform project, add this code to the button_click event.
private void button1_Click(object sender, EventArgs e) 
try { 
catch(Exception ex){ 

And the effect of the program is like that:
1. Click OpenExcel button  in the WindowForm

2. Open the Excel document, then it will locate to sheet3 by default.

Any further questions, please feel free to contact. Thank you!

Best Regards,
Amy Li



Answer 3

Hi szarcin,

How is this issue going on in your side? Have you solved the problem?

Best Regards,
Amy Li

Answer 4

Hi szarcin,

I will mark the answer for the thread. Any further questions, please feel free to follow up. Thank you!

Best Regards,
Amy Li


<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure