in reply to Win32::OLE - Excel, Can't save as Previous Version

When trying to figure out how to do something in Excel with Win32::OLE, I find it very useful to record a macros to do the task(s) and then check out the source code of the macros. Then I just grab the relevant portions and convert it into Perl code.

Since I happen to have access to a system with Excel 2007 installed on it, I created a blank Excel 2007 file (.xlsx file extension) and recorded a macros to save it as an Excel 2003 format file. Based on the macros source code, it looks like your file format is in correct. It should be xlExcel8.

Also, I pulled my source code of a script that I wrote late last year that did this exact thing. In that code, I had the file format as xlExcel8.

So just change the following line

$xlBook->SaveAs({Filename=>"$excelFile",FileFormat=>xlExcel9795});

so that it becomes the following

$xlBook->SaveAs({Filename=>"$excelFile",FileFormat=>xlExcel8});

Without testing the rest of your code, I think that should fix it. Of course, I'd suggest that you add in use strict; and use warnings; as davies suggested. Also, if you try his other suggestion of making Excel visible, it will help debug any situations where Excel is using a pop-up window to get input from the user. Once you've got the bugs worked out, you can set Excel to be invisible again if you don't want to watch Excel do what your script tells it to do.

Replies are listed 'Best First'.
Re^2: Win32::OLE - Excel, Can't save as Previous Version
by JaySal (Initiate) on Aug 26, 2011 at 17:03 UTC
    I checked excel's object browswer and xlExcel9597 seemed to be a valid option. I changed the xlexcel9597 to xlWorkbookNormal and that seemed to have solved the problem.
      I had the same issue but found the solution was to not use the drive letter specifier - it broke the saveas method. 'C:\temp\file.xls' did not work '\temp\file.xls' worked fine