Question:

VB.Net to MS Excel: How to customize borders and create new worksheets?

by  |  earlier

0 LIKES UnLike

Working on a VB.Net program using visual studio 2008. The program creates a report in an excel worksheet. I need to have some cells with custom borders on certain edges (above, below, left or right). At the moment, I can create a full border around a cell using this sample command:

myWorksheet.Cells(1,1).BorderAround (Excel.XlLineStyle.xlContinuous)

How do I modify that command to create borders on certain edges?

Also, what is the right command to create a new worksheet for each click on a button named "createNewWS"? It should be a new worksheet in the same excel file.

Thanks.

 Tags:

   Report

1 ANSWERS


  1. I would think you could record a macro while doing that in Excel and then copy that code into Vb.net.

    In Excel 2003 the (modified) code is

        Sheets(1).Select

        Sheets.Add

        Sheets(1).Move After:=Sheets(Sheets.Count)

        Sheets(Sheets.Count).Activate

    That selects the first worksheet, adds a new worksheet before it, and moves the new Sheets(1) after the last worksheet and activates it.  You can alter the last statement to put the new worksheet wherever you want.

    If you don't want default worksheet naming, the best place to name the worksheet is immediately after the Sheets.Add while it is still Sheets(1)

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.