Using c to select a worksheet in excel

0 votes

Using C# in .NET 3.5 with Visual Studio 2008, I am trying to set focus (or activate) a specific worksheet in an open workbook:

Here are some properties:

public Excel.Application xlApp {get;set;}
public Excel.Workbook xlWorkBook { get; set; }
public Excel.Worksheet xlWorkSheet { get; set; }
public Excel.Range range { get; set; }        

And here is how I am trying to select a specific worksheet:

(xlWorkSheet)Application.ActiveWorkbook.Sheets[FormControls.WorksheetFocus]).Select(Type.Missing);

And I have also tried this way:

((Excel.Worksheet)this.Application.ActiveWorkbook.Sheets[1]).Select();

What am I doing wrong? How do I select a specific worksheet in a workbook using C#?

Nov 14 in Others by Kithuzzz
• 20,660 points
35 views

1 answer to this question.

0 votes

Try this:

Excel.Worksheet xlWorkSheetFocus = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(2);
xlWorkSheetFocus.Activate();

I hope this helps you.

answered Nov 14 by narikkadan
• 37,660 points

Related Questions In Others

0 votes
1 answer

Convert table in a jpg image to excel using python

I believe you must execute OCR (optical ...READ MORE

answered Oct 16 in Others by narikkadan
• 37,660 points
252 views
0 votes
1 answer

how to select a statistical range in an excel

The lowest 5% and top 5% will ...READ MORE

answered Nov 4 in Others by narikkadan
• 37,660 points
33 views
0 votes
1 answer
0 votes
1 answer

Using office scripts to read superScripts characters from a cell in excel online

My understanding is that superscript and subscript ...READ MORE

answered Nov 17 in Others by narikkadan
• 37,660 points
26 views
0 votes
1 answer

Deleting duplicate rows in Excel using Epplus

You need to re-think this… the while ...READ MORE

answered Feb 23 in Database by gaurav
• 22,040 points
296 views
0 votes
1 answer

Export DataTable to Excel File

Add Interop References. First we need to ...READ MORE

answered Jun 9 in JQuery by gaurav
• 22,040 points
112 views
0 votes
1 answer

How to create and download excel document using asp.net

First, download the Open XML Format SDK 2.0. It comes ...READ MORE

answered Oct 3 in Others by narikkadan
• 37,660 points
145 views
0 votes
1 answer

Merge and export Excel/Word/PDF to PDF

Use GroupDocs.Merger for .NET API to merge Word, Excel, ...READ MORE

answered Oct 3 in Others by narikkadan
• 37,660 points
85 views
0 votes
1 answer

Using a UDF in Excel to update the worksheet

The MSDN KB is incorrect. It says A user-defined function called ...READ MORE

answered Nov 7 in Others by narikkadan
• 37,660 points
37 views
0 votes
1 answer

How to insert a new row in the specified cell only, of Excel sheet using c#?

I have this worksheet with a matrix ...READ MORE

answered Nov 24 in Others by narikkadan
• 37,660 points
26 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP