Author Topic: Excel Saveas  (Read 2465 times)

mathia

  • Newbie
  • *
  • Posts: 43
Excel Saveas
« 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')

Deana

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: Excel Saveas
« Reply #1 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
objexcel.worksheets('sheet1').SaveAs ('FileName:="C:\q2\test.csv", Fileformat:=6')
 
To :
Code: Winbatch
objexcel.worksheets('sheet1').SaveAs (::'FileName="C:\q2\test.csv", Fileformat=6')

Deana F.
Technical Support
Wilson WindowWare Inc.

td

  • Tech Support
  • *****
  • Posts: 3073
    • WinBatch
Re: Excel Saveas
« Reply #2 on: April 21, 2014, 08:09:04 am »
Drop the single quotes too

Code: Winbatch
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

  • Newbie
  • *
  • Posts: 43
Re: Excel Saveas
« Reply #3 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.