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, 2022 in Others by Kithuzzz
• 38,000 points
629 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, 2022 by narikkadan
• 63,600 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, 2022 in Others by narikkadan
• 63,600 points
2,296 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, 2022 in Others by narikkadan
• 63,600 points
729 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, 2022 in Others by narikkadan
• 63,600 points
790 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, 2022 in Database by gaurav
• 23,260 points
1,514 views
0 votes
1 answer

Export DataTable to Excel File

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

answered Jun 9, 2022 in JQuery by gaurav
• 23,260 points
784 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, 2022 in Others by narikkadan
• 63,600 points
2,961 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, 2022 in Others by narikkadan
• 63,600 points
1,507 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, 2022 in Others by narikkadan
• 63,600 points
739 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, 2022 in Others by narikkadan
• 63,600 points
2,360 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