in reply to Win32::OLE(0.1702) error 0x80020011

Hey, except for the cryptic error this code is really neat. I didn't realize you could export embedded charts to .gifs like that. I suppose I will hang onto this.

At any rate, your code bombs out because you are trying to use the Windows handle when you really do not need to. Here is a slightly modified version of your code:

... $file = "C:\\testw.txt"; open (TTT, ">$file") || die "error"; $filename = "C:\\temp\\frufru.xls"; $filter = 'gif'; # can be GIF, JPG, JPEG or PNG $pngnm = "C:\\test"; eval{ my $Excel = Win32::OLE->new('Excel.Application', 'Quit'); # use the Ex +cel application if it's open, otherwise open new #why in the hell would you want to do this? #$hwnd = $Excel->{"Hwnd"}; #Hell no print TTT $hwnd; die "Cannot find $filename" unless (-e $filename); my $Book = $Excel->Workbooks->Open( $filename ); # open the file foreach my $Sheet (in $Book->Sheets) { ...
I created a single workbook with three spreadsheets and two charts (on the first and second sheet). I debugged all the way until it created the first chart and got bored. Looks like it will work. What's different? Well, notice I commented out the following line:
#$hwnd = $Excel->{"Hwnd"};
Grabbing the Windows handle to Excel is unnecessary since you already have a working one. I suspect you are using some deprecated example code.

I also noticed some people made a few style points about this code. I will add a few also:

  • You have lots of hard coded paths in this. You might try using the GetOpt::Long module to make is reusable.
  • You didn't check to see if the .xls file actually existed before trying to open and work with it.
  • Are you certain you want one big eval() around this whole thing or wouldn't you rather have a few evals around different areas that are likely to fail so that you can recover? For instance, you may want to look for a given file in an alternative location?
  • And yes, you REALLY must use strict. Really.

    Celebrate Intellectual Diversity