how to use visual basic excel code example

Example 1: create new worksheet excel visual basic

Imports Excel = Microsoft.Office.Interop.Excel

Dim ExcelApp As New Excel.Application
Dim ExcelWorkBook As Excel.Workbook
Dim ExcelWorkSheet As Excel.Worksheet

ExcelApp.Workbooks.Open("ExcelFileName")
ExcelWorkBook = ExcelApp.ActiveWorkbook

PreviousSheetName = ExcelWorkBook.Sheets(ExcelWorkBook.Sheets.Count).Name

ExcelWorkBook.Sheets.Add(After:=ExcelWorkBook.Sheets(PreviousSheetName)).Name = "New Sheet Name"

Example 2: how save excel through visual basic

ExcelWorkBook.Save

Tags:

Vb Example