in reply to Adding MSWord custom properties in Win32::OLE

I can't give you much detail, but in our snippets collection from 5 or 6 years ago (Perl 5.6 days?) I found this:
use strict; use Win32::OLE qw(in); use Win32::OLE::Const 'Microsoft Office'; my $Doc = Win32::OLE->GetObject('g:\scratch\test.doc'); if ( ( 0 + Win32::OLE::LastError() ) != 0 ) { $Doc->CustomDocumentProperties->Add( { Name => 'A custom property', LinkToContent => 0, Type => msoPropertyTypeString, Value => "Whatever" } ); }
At the time we were doing lots of MS stuff, fortunately those days are now long past, but maybe this will help.

jdtoronto

Replies are listed 'Best First'.
Putting it all together
by thoglette (Scribe) on Sep 06, 2006 at 05:06 UTC
    Thanks. A little fettling gets the job done. Win32::OLE makes a whole lot of function calls look like empty hash references. But an empty hash ref is not undefined and can be tested for.
    $docprops = $doc->CustomDocumentProperties(); unless (defined ($doc->CustomDocumentProperties($property))) { $docprops->Invoke('Add', { Name => $property, LinkToContent => 0, Type => 4, #msoPropertyTypeString #strictures to work around still Value => $value, }); } $doc->CustomDocumentProperties($property)->{Value} = $value;
    It looks a little weird in the debugger, as the fact that the value is set is hidden for a little while (value is ''). Suspect it's a debugger/tie/Windows interaction.

    Thoglette.

    --
    Butlerian Jihad now!