use Win32::OLE; use Win32::Semaphore; $excel = Win32::OLE->GetActiveObject("Excel.Application"); if (!$excel) { print "Not found, locking\n"; my $sem = Win32::Semaphore->new(1, 1, 'ASGdailyreport_StartExcel'); $sem->wait(); print "locked, looking again\n"; $excel = Win32::OLE->GetActiveObject("Excel.Application"); if (!$excel) { print "still not found, starting\n"; $excel = Win32::OLE->new('Excel.Application') or die "oops\n"; # or # $excel = Win32::OLE->new('Excel.Application','Quit') or die "oops\n"; # if you wish the Excel to quit once the last script using it exits } $sem->release(); print "unlocked\n"; } if (!$excel) { die "Could not connect to or start MS Excel!\n"; } print "have an excel $excel\n";