Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Win32::OLE->GetObject Fails on MS Word Document

by davies (Prior)
on Dec 16, 2020 at 22:39 UTC ( [id://11125313]=note: print w/replies, xml ) Need Help??


in reply to Win32::OLE->GetObject Fails on MS Word Document

Try something like:

use strict; use warnings; use Win32::OLE; my $word = Win32::OLE->new('Word.Application'); $word->{Visible} = 1; my $filename = 'C:/tmpx/test.docx'; my $document = $word->Documents->Open($filename);

GetObject is something I rarely use or recommend. It is trying to take control of an existing instance of word, which may be doing anything. Create your own instance and you know it's clean. There isn't an instance of an application called "C:\\tmpx\\test.docx" for Perl to grab (although there may be an instance of word that is using this file), so it fails quite correctly.

Regards,

John Davies

Update: fixed typo in text

Replies are listed 'Best First'.
Re^2: Win32::OLE->GetObject Fails on MS Word Document
by roho (Bishop) on Dec 16, 2020 at 22:45 UTC
    Thank you davies. That works fine. Leaves me wondering what (if anything) GetObject is good for.

    "It's not how hard you work, it's how much you get done."

      If you really need to access a running instance, that's what GetObject does. It's very rare, but can be useful if you are doing weird things and can end up with invisible instances that you want to close down elegantly rather than through the task manager. It can also be useful if you need to do some manual work first and then let the code take over.

      Regards,

      John Davies

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11125313]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-03-28 17:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found