How can I open a Word document read-only with Perl?

Is there any method inside Perl that will allow me to get an object in read-only mode to avoid a dialog box popping up if the file is locked by another user?

$document = Win32::OLE->GetObject("$docFile")
    or die "can't open $docFile";
+5
source share
1 answer

This is because you are doing it wrong. GetObjectjust opens the object with default behavior. You must create an object Word.Application:

 my $word = Win32::OLE->new( 'Word.Application' );

Then use the Documentscollection method Openwith the specified parameter ReadOnly. For example:

 $doc = $word->Documents->Open( { FileName => $document_path,
                                , ReadOnly => 1
                                } );

Read http://msdn.microsoft.com/en-us/library/bb216319.aspx for syntaxDocuments.Open

+10

All Articles