Excel Sheet issue

Hi All,

I am creating excel charts for my application…I am creating pivot tables and charts .So i have to use more than one sheet.

Set excelApp = CreateObject(“Excel.Application”)

excelApp.SheetsInNewWorkbook = 1

call excelApp.Workbooks.Add

'Code to add data to first sheet

I am activating second sheet using following code

excelApp.Workbooks(1).Worksheets(1).Activate

excelApp.Workbooks(1).Worksheets(1).Name= “PivotSheet”

in my system it is creating second sheet …but it is not working in users system.

is it due to excel setting or error in my coding?

i have used

excelApp.Workbooks(1).Worksheets(“Sheet2”).Activate

excelApp.Workbooks(1).Worksheets(“Sheet2”).Name= “PivotSheet”

Same is also not working always.

How i can write code to activate sheet successfully irrespective of users excel sheet setting?

Subject: Excel Sheet issue

try this

Dim oExcel As Object

    Dim oBook As Object

    Dim oSheet As Object



    'Start a new workbook in Excel.

    oExcel = CreateObject("Excel.Application")

    oBook = oExcel.Workbooks.Add



    'Add data to cells of the first worksheet in the new workbook

Worksheets.Add().Name = “MySheet”

Worksheets.Add().Name = “MySheet1”

    oSheet = oBook.Worksheets(1)

    oSheet.Range("A1").Value = "Last Name"

    oSheet.Range("B1").Value = "First Name"

  

    oSheet = oBook.Worksheets(2)

    oSheet.Range("A1").Value = "Last Name Sheet 2"

    oSheet.Range("B1").Value = "First Name Sheet 2"  



    'Save the Workbook and quit Excel.

    oBook.SaveAs(sSampleFolder & "Book1.xls")

    oSheet = Nothing

    oBook = Nothing

    oExcel.Quit()

    oExcel = Nothing