none
how to add a excel sheet

    Question

  • hi,

    i want to do some functions in one excel document and

    also i want to open another excel document by the way and i need to add it like what we done in word wordApp.Documents.Add can anybody help me to do this in excel sir?

    Friday, February 10, 2012 6:03 AM

Answers

  • Hi,

    Is the following code what you are looking for?

                Excel.Application oExcel = new Excel.Application();
                oExcel.Visible = true;
                //add a new blank workbook
                Excel.Workbook oBook = oExcel.Workbooks.Add();
                Excel.Worksheet oSheet1 = oBook.Worksheets[1] as Excel.Worksheet;
                //add a new blank worksheet after the first worksheet
                Excel.Worksheet oSheet = oBook.Worksheets.Add(After: oSheet1);

    I hope this helps.

    Calvin Gao[MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, February 28, 2012 7:38 AM

All replies

  • I can give you the code but first would you like recording a macro to see what the code looks like? :)

    Sid (A good exercise for the Heart is to bend down and help another up) Please do not email me your questions. I do not answer questions by email unless I get paid for it :) If you want, create a thread in VB.Net/Excel forum and email me the link and I will help you if I can.

    Friday, February 10, 2012 6:13 AM
  • yes sure sir. please send me the code
    Friday, February 10, 2012 1:20 PM
  • Hi,

    Is the following code what you are looking for?

                Excel.Application oExcel = new Excel.Application();
                oExcel.Visible = true;
                //add a new blank workbook
                Excel.Workbook oBook = oExcel.Workbooks.Add();
                Excel.Worksheet oSheet1 = oBook.Worksheets[1] as Excel.Worksheet;
                //add a new blank worksheet after the first worksheet
                Excel.Worksheet oSheet = oBook.Worksheets.Add(After: oSheet1);

    I hope this helps.

    Calvin Gao[MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, February 28, 2012 7:38 AM