Excel Saveas

Started by mathia, April 21, 2014, 06:22:09 AM

Previous topic - Next topic

mathia

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')

Deana

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')

Deana F.
Technical Support
Wilson WindowWare Inc.

td

Drop the single quotes too

Code (winbatch) Select
objexcel.worksheets('sheet1').SaveAs (::FileName="C:\q2\test.csv", Fileformat=6)
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

mathia

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.