in reply to Win32::OLE problem with Destructing

I'm in a bit of a hurry, but I'll UPDATE this when I get home. Until then, here's some food for thought:

$Doc->Activate(); $Doc->SaveAs ('F:\\dev\\experiment\\ScanWord\\foobar.doc');

You need to have an "Active Document" for it to work. You might also have to instantiate an object pointing at word specifically to use
$Word->ActiveDocument->SaveAs()

use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Word'; $Win32::OLE::Warn = 2; # Throw Errors, I'll catch them my $Word = Win32::OLE->GetActiveObject('Word.Application') || Win32::OLE->new('Word.Application', 'Quit'); my $Doc = Win32::OLE->GetObject($wrdfile) || die &CheckError(); #### or #### my $Doc = $Word->Documents->Open($wrdfile) || die &CheckError();
C-.

Replies are listed 'Best First'.
Re: Re: Win32::OLE problem with Destructing
by John M. Dlugosz (Monsignor) on Jul 21, 2001 at 00:52 UTC
    Why should it have to be active before it can be saved, if I'm telling it which object to use?

    I think it's a bug, because if I have Word open it doesn't object to that! Even though this document never shows up in the Word interactive application. So perhaps Word is getting an internal error because at some point it assumes that there is some Active document and dereferencing it or something?

    —John

      Was that the solution, then?

      A document doesn't close itself, the application does it.

      You are telling the word application implicitly that you want the object that it is working on to be the 'Active' document. It doesn't have to be active for many (most) functions/methods/objects to be referenced, but Close is an exception. It's true with all of the office applications. The Application Engine needs to activate implicitly the open object that needs to be acted on, etc.

      You can also name the document specifically through the application object:

      $Word->$Documents($Docname)->SaveAs($filename); $Word->$Documents($Docname)->Close; undef $Doc;

      if the document already has a name.

      C-.