WinBatch® Technical Support Forum

Archived Boards => COM Automation and dotNet => Topic started by: mathia on April 21, 2014, 06:22:09 AM

Title: Excel Saveas
Post by: mathia on April 21, 2014, 06:22:09 AM
Having a bit of trouble using the SaveAs option when automating Excel.  I don't get any error details other than "Document not saved".  Does anyone have experience with using this particular method in Winbatch?  I am using Excel 2010.  Everything works up to the last line.  Here is the code that I am trying to implement:

   objexcel=objectopen("excel.application")
   objexcel.visible=@true
   objExcel.Application.DisplayAlerts = @False
   file='C:\q2\estatements\03.28.14.xlsx'
   exlBook=objexcel.workbooks.open("%file%")
   count=exlbook.sheets.count
   if count >1 then objexcel.worksheets('sheet2').delete
   curr=objexcel.Worksheets("sheet1")
   ColSheets=exlbook.Sheets
   
   exlsheet=exlbook.ActiveSheet.name
   curr.activate
   objexcel.worksheets('sheet1').SaveAs ('FileName:="C:\q2\test.csv", Fileformat:=6')
Title: Re: Excel Saveas
Post by: Deana on April 21, 2014, 07:48:22 AM
You will need to modify the syntax for WIL. Notice the change to the format of the data passed to the SaveAs Method.

Change this line:
Code (winbatch) Select
objexcel.worksheets('sheet1').SaveAs ('FileName:="C:\q2\test.csv", Fileformat:=6')

To :
Code (winbatch) Select
objexcel.worksheets('sheet1').SaveAs (::'FileName="C:\q2\test.csv", Fileformat=6')

Title: Re: Excel Saveas
Post by: td on April 21, 2014, 08:09:04 AM
Drop the single quotes too

Code (winbatch) Select
objexcel.worksheets('sheet1').SaveAs (::FileName="C:\q2\test.csv", Fileformat=6)
Title: Re: Excel Saveas
Post by: mathia on April 21, 2014, 09:43:18 AM
EXCELLENT!!!!!
Thanks so much. I've been banging my head against the wall on that one for a bit.  I can move on to the next challenge in that program now.