Home > Testing > How to add a sheet in Excel through VB Scripting.

How to add a sheet in Excel through VB Scripting.

Please find the code.

Set obj_ExcelSheet = CreateObject(“Excel.Application”)’ creating the excel object

obj_ExcelSheet.visible = True

obj_ExcelSheet.SheetsInNewWorkbook = 1 ‘ no of sheets to be added

obj_ExcelSheet.Workbooks.Add() ‘ actually adding the sheet to the file

obj_ExcelSheet.Worksheets(1).Activate ‘ make the sheet no-1 activate

obj_ExcelSheet.Activesheet.Name = “Check” ‘name of the sheet

obj_ExcelSheet.ActiveWorkbook.saveas (“C:\Documents and Settings\username\Desktop\MF.xls”) ‘saving the file in desired location.

obj_ExcelSheet.quit ‘ quiting from the excel.

Set obj_ExcelSheet = nothing

Please provide your feedback.

Reblog this post [with Zemanta]
Advertisements
  1. December 26, 2011 at 3:40 pm

    Nice and informative blog.Please update with new things so that we can learn too.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: