Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: Win32 OLE Word Add Password?

by Anonymous Monk
on Sep 27, 2016 at 21:51 UTC ( [id://1172785]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Win32 OLE Word Add Password?
in thread Win32 OLE Word Add Password?

So I only researched this problem under Perl, forgetting that you have to hunt around under VB to find answers like this. Turns out it is possible, and easier than I imagined.
#!/usr/bin/perl -w use Win32::OLE; use Win32::OLE::Const; my $wd = Win32::OLE::Const->Load("Microsoft Word 14.0 Object Library") +; my $word = Win32::OLE->GetActiveObject('Word.Application') || Win32::OLE->new('Word.Application','Quit') or die Win32::OLE->LastError(); $word->{Visible} = 1; $filename = 'foobar.doc'; $pw = 'foobar'; $savename = 'foobarsave.doc'; my $doc = $word->Documents->Open($docname) or die Win32::OLE->LastError(); $doc->SaveAs( { FileName => $savename, Password => $pw}); $doc->close; $word->close;
However, there are some hitches. There is apparently no way to just save the same file with a password, or if there is I couldn't find it. If you execute the SaveAs statement above with the same filename nothing happens--i.e. there is no error, nothing gets saved, and no password is added. You have to save it with a different name like I did in the example code. It might work if you changed the file in some way, like adding a space at the end, but I didn't try this.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-24 13:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found