cancel
Showing results for 
Search instead for 
Did you mean: 

Create new excel from data

NisHera
Valued Contributor

Create new excel from data

Hi

I was trying to create an XL using some data in script 

but failed following are my coding please help me correcting it




Sub Main


 Dim fileName, sheetName


 fileName ="C:\N2014_1\TaxCalculation\logs26.xlsx"


 sheetName ="Logs1"


 


 Call WriteLogs(fileName,sheetName)


End Sub


 


Sub WriteLogs(fname,sname)


Dim app,book,sste, row, col


 


Set app = CreateObject("Excel.Application")


Set book = app.Workbooks.Add()


  book.saveAs fname


  


  Set app = Sys.OleObject("Excel.Application")


  Set book = app.Workbooks.Open(fname)


  Set sste = book.Sheets(sname) '------hear it says Subscript out of range ????-----------


 


  app.Application.Visible = True


  app.DisplayAlerts = False


  


  For row=0 to 5


for col = 0 to 4


app.book.sheet.Cells(row,col) =row&","& col


Next


Next


 


   Book.SaveAs fname


  .Book.Close


  


app.Appliaction.Quit


End Sub

1 REPLY 1
murugans1011
Regular Contributor

RE: Create new excel from data

you are creating a new excel by using 'save as' method....but u r opening non existent sheet ....... by default excel will create a sheet name as 'sheet1'. so try



            sheetName ="sheet1"

        

            function

            Set sste = book.Sheets(sname)


           End function
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors