I've got some code to update custom properties - in essence
$property = "FooBar";
$doc->CustomDocumentProperties($property)->{Value} = $text_value;
However, this warns
Can't use an undefined value as a HASH reference at C:\Public\Projects\gold\update_msword.pl
if the custom property does not already exist.
The appropriate VBA code is...
'If customdocument property did not exist, create it
If Err.Number <> 0 Then
Set DocProps = ThisWorkbook.CustomDocumentProperties
DocProps.Add Name:="FooBar", _
LinkToContent:=False, _
Type:=msoPropertyTypeString, _
Value:=str_content
End If
Which leads the following questions under Win32::OLE
- Where is Err.Number ? And I'd like to avoid the warn, so how can I see what custom properties exist.
- $doc->CustomDocumentProperties and $doc->{CustomDocumentProperties} both return undef, so how does one create $doc_props?
- is msoPropertyTypeString a constant constant or yet another $$wd{'msoPropertyTypeString'}, (where $wd=Win32::OLE::Const->Load($MSWord);)
-
I realise that my lack of understanding of VBA is not helping. If there's a book worth purchasing, suggestions would be welcomed!
Update 2006-09-06
- The error code is Win32::OLE::LastError(); - See perldoc Win32::OLE
- but you need to Win32::OLE->Option(Warn=>0); to avoid having errors stop the debugger.
- A better solution is to pre-test-for-existance, rather than post-test-for-error. See my followup post
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.