http://www.perlmonks.org?node_id=414614


in reply to Avoiding Win32::OLE errors

I'm relatively new to PerlMonks so I wasn't sure whether I should respond to the others' comments on this subject or not. The suggestions offered here were interesting and led to some useful information but did not solve the problem. However I did find a hokey way around this specific case. In this situation it appears that closing Word causes the $word object to point to invalid stuff and that is what seems to be causing the error messages. I experimented with various combinations and found that the following code bypasses the problem of the Perl script being terminated although there is still a warning message issued. The code that seems to work for this case is:
$icount = $word->Documents->Count(); $done = 0; while ($done == 0) { if ($word->Documents) { if (($mycnt = $word->Documents->Count()) != $icount) { $done = 1; } } else { undef $word; $word = Win32::OLE->GetActiveObjectord.Application') || Win32::OLE->new('Word.Application'); $done = 1; } sleep 5; }
As I say, it's hokey but it seems to work for this specific case.