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.


In reply to Re: Win32::OLE - Excel, Can't save as Previous Version by dasgar
in thread Win32::OLE - Excel, Can't save as Previous Version by JaySal

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.