In Re^2: Finding out Excel 'variables', I reproduced ActiveState's code for listing Excel's constants and values. I think it would be relatively simple to adapt this to other libraries. I would therefore start thinking along the following lines:

Which constants vary from one version to the next? My first guess would be "None", meaning that each later version is likely to be a superset of the previous one.

If any constant does in fact vary, how would I know which to use? If you have or can get (not all that difficult in Excel) the version number, you might try creating your own hash of hashes containing all the constants, so that you would have a key, say xlVisible, and a hashref giving you the constant values for each version of the library that you have available. This means a large data structure, so my next thought would be to isolate the constants that are actually used. Again, if they are all the same, just use the latest version.

Another option is not to use constants at all, but magic numbers. This isn't ideal, but sometimes it's the least work, especially if the constant isn't in the library. So, when writing Perl to control Excel, I frequently write something like:

$object->Color = 255 #vbRed

It would be simple to take this farther and write ones own constants if the magic number were to be used more than once.

Regards,

John Davies

Update: Dasgar's reply, written while I was writing mine, looks much better at first sight.

Update 2: fixed minor typo


In reply to Re: How to use win32::OLE with multiple versions of Microsoft Office? by davies
in thread How to use win32::OLE with multiple versions of Microsoft Office? by frida

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.