home *** CD-ROM | disk | FTP | other *** search
/ Chip: Windows 2000 Professional Resource Kit / W2KPRK.iso / apps / perl / ActivePerl.exe / data.z / perlwin32faq12.html < prev    next >
Encoding:
Extensible Markup Language  |  1999-10-15  |  25.0 KB  |  679 lines

  1. <?xml version="1.0"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  3.     "http://www.w3.org/TR/xhtml1/DTD/transitional.dtd">
  4. <html xmlns="http://www.w3.org/TR/xhtml1">
  5.   <head>
  6.     <title>perlwin32faq12 - Using OLE with Perl</title>
  7.     <link rev="made" href="mailto:hmn@datagraf.dk" />
  8.     <meta name="GENERATOR" charset="iso-8859-1" />
  9.     <link rel="STYLESHEET" href="../win32prk.css" type="text/css"
  10.     media="screen" />
  11.   </head>
  12.  
  13.   <body bgcolor="#ffffff">
  14.     <!-- beginning of leaf header-->
  15.  
  16.     <table width="100%">
  17.       <tr>
  18.         <td bgcolor="000000" width="70" height="31"><a href= 
  19.         "http://www.activestate.com/"><img src="ASbutton.gif" alt= 
  20.         "ActiveState Home Page" border="0" width="68" height=
  21.         "30" /></a></td>
  22.  
  23.         <td width="10" bgcolor="#ffffff"> </td>
  24.  
  25.         <td valign="middle" bgcolor="#cc0066"><font face=
  26.         "sans-serif" size="+1" color="#ff99cc">   
  27.         Win32 FAQ</font></td>
  28.       </tr>
  29.     </table>
  30.     <!-- end of leaf content--><!-- INDEX BEGIN -->
  31.  
  32.     <ul>
  33.       <li><a href="#NAME">NAME</a></li>
  34.  
  35.       <li>
  36.         <a href="#DESCRIPTION">DESCRIPTION</a> 
  37.  
  38.         <ul>
  39.           <li><a href="#use_ole">Can I use OLE with Perl?</a></li>
  40.  
  41.           <li><a href="#changed_by_4xx">What has changed with OLE
  42.           since build 3xx</a></li>
  43.  
  44.           <li><a href="#print_word">How do I print a Microsoft Word
  45.           document?</a></li>
  46.  
  47.           <li><a href="#extract_cells">How do I extract a series of
  48.           cells from Microsoft Excel?</a></li>
  49.  
  50.           <li><a href="#make_chart">How do I make a chart in
  51.           Microsoft Excel?</a></li>
  52.  
  53.           <li><a href="#save_chart">How do I save a chart from
  54.           Microsoft Excel as GIF/JPEG/PNG?</a></li>
  55.  
  56.           <li><a href="#run_macro">How do I run a macro in
  57.           Microsoft Excel?</a></li>
  58.  
  59.           <li><a href="#set_name_cell">How do I set the name of a
  60.           cell in Microsoft Excel?</a></li>
  61.  
  62.           <li><a href="#create_new_folder">How do I create a new
  63.           folder in Outlook?</a></li>
  64.  
  65.           <li><a href="#use_ado">How do I use ADO?</a></li>
  66.  
  67.           <li><a href="#use_notes">How do I use Lotus
  68.           Notes?</a></li>
  69.  
  70.           <li><a href="#set_printer">How do I set the
  71.           printer?</a></li>
  72.  
  73.           <li><a href="#convert_vba">How do I convert a VBA macro
  74.           to Perl?</a></li>
  75.  
  76.           <li><a href="#find_docs">Where do I find documentation
  77.           for the object models?</a></li>
  78.  
  79.           <li><a href="#find_constants">OK, but can I at least find
  80.           the constants that are exported from
  81.           Win32::OLE::Const?</a></li>
  82.  
  83.           <li><a href="#errors">Why doesn't $! get set with the
  84.           error message I am generating?</a></li>
  85.  
  86.           <li><a href="#odbc_ole">Why do I get an error when using
  87.           ODBC and OLE?</a></li>
  88.  
  89.           <li><a href="#strict">Why doesn't it work - even after
  90.           all this?</a></li>
  91.         </ul>
  92.       </li>
  93.  
  94.       <li><a href="#AUTHOR_AND_COPYRIGHT">AUTHOR AND
  95.       COPYRIGHT</a></li>
  96.     </ul>
  97.     <!-- INDEX END --><br />
  98.     <hr />
  99.     <br />
  100.     <br />
  101.      
  102.  
  103.     <h1><a name="NAME">NAME</a></h1>
  104.  
  105.     <p>perlwin32faq12 - Using OLE with Perl</p>
  106.     <br />
  107.     <hr />
  108.     <br />
  109.     <br />
  110.      
  111.  
  112.     <h1><a name="DESCRIPTION">DESCRIPTION</a></h1>
  113.  
  114.     <p>How to use OLE automation with Perl - through the Win32::OLE
  115.     module</p>
  116.     <a name="use_ole"></a>
  117.     <hr />
  118.  
  119.     <h1>Can I use OLE with Perl?</h1>
  120.  
  121.     <p>Yes - otherwise this FAQ wouldn't have been a separate FAQ,
  122.     but just part of perlwin32faq4 ;-)</p>
  123.  
  124.     <p>If you want to use OLE with Perl you need the Win32::OLE
  125.     module. And you need to read the documentation that comes with
  126.     it.</p>
  127.  
  128.     <p><code>use Win32::OLE</code> doesn't export any variables and
  129.     functions to the main namespace, so if you want easy access to
  130.     the <code>in</code> and <code>with</code> functions you should
  131.     load the module with</p>
  132.  
  133.     <blockquote>
  134.       <p><code>use Win32::OLE qw(in with);</code></p>
  135.     </blockquote>
  136.     <a name="changed_by_4xx"></a>
  137.     <hr />
  138.  
  139.     <h1>What has changed with OLE since build 3xx</h1>
  140.  
  141.     <p>A lot - Gurusamy Sarathy and then Jan Dubois redesigned the
  142.     code and added a bundle of enhancements. Old scripts should run
  143.     with little or no modifications. When writing new scripts there
  144.     is no excuse for not using the new Win32::OLE module
  145.     options.</p>
  146.  
  147.     <p>Look at the Win::OLE module documentation (under
  148.     Incompatibilities) and in particular the <a href= 
  149.     "release.htm#Whats_Changed">'What's changed from 300 series
  150.     builds'</a> in the release notes.</p>
  151.     <a name="print_word"></a>
  152.     <hr />
  153.  
  154.     <h1>How do I print a Microsoft Word document?</h1>
  155.  
  156.     <p>Use the method PrintOut on a document object, for
  157.     example:</p>
  158.  
  159.     <blockquote>
  160.       <p><code>use strict;<br />
  161.       use Win32::OLE;<br />
  162.       use Win32::OLE::Const 'Microsoft Word';<br />
  163.       <br />
  164.       my $Word = Win32::OLE->new('Word.Application',
  165.       'Quit');<br />
  166.       # $Word->{'Visible'} =
  167.       1;         # if
  168.       you want to see what's going on<br />
  169.       $Word->Documents->Open("C:\\DOCUMENTS\\test.doc")<br />
  170.           || die("Unable to open document ",
  171.       Win32::OLE->LastError());<br />
  172.       $Word->ActiveDocument->PrintOut({<br />
  173.           Background => 0,<br />
  174.           Append     =>
  175.       0,<br />
  176.           Range      =>
  177.       wdPrintAllDocument,<br />
  178.           Item       =>
  179.       wdPrintDocumentContent,<br />
  180.           Copies     =>
  181.       1,<br />
  182.           PageType   =>
  183.       wdPrintAllPages,<br />
  184.       });</code></p>
  185.     </blockquote>
  186.  
  187.     <p>or simply</p>
  188.  
  189.     <blockquote>
  190.       <p><code>$Word->ActiveDocument->PrintOut;</code></p>
  191.     </blockquote>
  192.     <a name="extract_cells"></a>
  193.     <hr />
  194.  
  195.     <h1>How do I extract a series of cells from Microsoft
  196.     Excel?</h1>
  197.  
  198.     <p>If you have a sheet object you can extract the values of a
  199.     series of cells through $Sheet->Range->{'Value'}, for
  200.     example:</p>
  201.  
  202.     <blockquote>
  203.       <p><code>my $array =
  204.       $Sheet->Range("A8:B9")->{'Value'};</code></p>
  205.     </blockquote>
  206.  
  207.     <p>Now $array[0][0] contains the value of cell A8, $array[0][1]
  208.     the value of cell B8, $array[1][0] the value of cell A9 and
  209.     $array[1][1] the value of cell B9.</p>
  210.  
  211.     <p>What is returned is an two-dimensional array (OK, an array
  212.     with references to arrays) that contains the values of the
  213.     requested cells.</p>
  214.  
  215.     <p>A complete example is here:</p>
  216.     <br />
  217.  
  218.     <blockquote>
  219.       <code>use strict;<br />
  220.       use Win32::OLE qw(in with);<br />
  221.       use Win32::OLE::Const 'Microsoft Excel';<br />
  222.       $Win32::OLE::Warn =
  223.       3;                                #
  224.       die on errors...<br />
  225.       my $Excel =
  226.       Win32::OLE->GetActiveObject('Excel.Application')<br />
  227.           ||
  228.       Win32::OLE->new('Excel.Application', 'Quit');  #
  229.       get already active Excel<br />
  230.                                                             #
  231.       application or open new<br />
  232.       my $Book =
  233.       $Excel->Workbooks->Open("C:\\DOCUMENTS\\test.xls"); #
  234.       open Excel file<br />
  235.       my $Sheet =
  236.       $Book->Worksheets(1);                     #
  237.       select worksheet number 1<br />
  238.       my $array =
  239.       $Sheet->Range("A8:B9")->{'Value'};        #
  240.       get the contents<br />
  241.       $Book->Close;<br />
  242.       foreach my $ref_array (@$array)
  243.       {                     #
  244.       loop through the array<br />
  245.                                                             #
  246.       referenced by $array<br />
  247.           foreach my $scalar (@$ref_array)
  248.       {<br />
  249.               print
  250.       "$scalar\t";<br />
  251.           }<br />
  252.           print "\n";<br />
  253.       }</code>
  254.     </blockquote>
  255.     <br />
  256.     <br />
  257.      
  258.  
  259.     <p>To retrieve the formatted value of a cell you should use the
  260.     <code>{'Text'}</code> property instead of the <code>
  261.     {'Value'}</code> property. This returns exactly what is being
  262.     displayed on the screen though! If the column is not wide
  263.     enough, you get a value of '######':</p>
  264.  
  265.     <blockquote>
  266.       <p><code>my $array =
  267.       $Sheet->Range("A8:B9")->{'Text'};</code></p>
  268.     </blockquote>
  269.     <a name="make_chart"></a>
  270.     <hr />
  271.  
  272.     <h1>How do I make a chart in Microsoft Excel?</h1>
  273.  
  274.     <p>A good idea would be to record a macro in Microsoft Excel
  275.     and then <a href="#convert_vba">convert it to Perl</a>. But
  276.     here is a complete example:</p>
  277.  
  278.     <blockquote>
  279.       <p><code>use strict;<br />
  280.       use Win32::OLE;<br />
  281.       use Win32::OLE::Const 'Microsoft Excel';<br />
  282.       <br />
  283.       my $Excel = Win32::OLE->new("Excel.Application");<br />
  284.       $Excel->{Visible} = 1;<br />
  285.       <br />
  286.       my $Book = $Excel->Workbooks->Add;<br />
  287.       my $Sheet = $Book->Worksheets(1);<br />
  288.       my $Range = $Sheet->Range("A2:C7");<br />
  289.       $Range->{Value} =<br />
  290.           [['Delivered', 'En route', 'To be
  291.       shipped'],<br />
  292.            [504, 102, 86],<br />
  293.            [670, 150, 174],<br />
  294.            [891, 261, 201],<br />
  295.            [1274, 471, 321],<br />
  296.            [1563, 536, 241]];<br />
  297.       <br />
  298.       my $Chart = $Excel->Charts->Add;<br />
  299.       $Chart->{ChartType} = xlAreaStacked;<br />
  300.       $Chart->SetSourceData({Source => $Range, PlotBy =>
  301.       xlColumns});<br />
  302.       $Chart->{HasTitle} = 1;<br />
  303.       $Chart->ChartTitle->{Text} = "Items delivered, en route
  304.       and to be shipped";</code></p>
  305.     </blockquote>
  306.     <a name="save_chart"></a>
  307.     <hr />
  308.  
  309.     <h1>How do I save a chart from Microsoft Excel as
  310.     GIF/JPEG/PNG?</h1>
  311.  
  312.     <p>You can use the Export method of a chart. If you have a
  313.     chartobject the code looks like this</p>
  314.  
  315.     <blockquote>
  316.       <p><code>$ChartObj->Chart->Export({<br />
  317.           FileName    =>
  318.       "$graphics_filename",<br />
  319.           FilterName  =>
  320.       'GIF',<br />
  321.           Interactive =>
  322.       0});</code></p>
  323.     </blockquote>
  324.  
  325.     <p>A complete example that opens an Excel workbook, loops
  326.     through all the charts and saves them as GIFs and then closes
  327.     the Excel workbook is here:</p>
  328.  
  329.     <blockquote>
  330.       <p><code>use strict;<br />
  331.       use Win32::OLE qw(in with);<br />
  332.       use Win32::OLE::Const;<br />
  333.       use Win32::OLE::Const 'Microsoft Excel';<br />
  334.       $Win32::OLE::Warn =
  335.       3;        # die on
  336.       errors...<br />
  337.       <br />
  338.       my $filename = 'c:\\documents\\test.xls';<br />
  339.       my $filter =
  340.       'GIF';           #
  341.       can be GIF, JPG, JPEG or PNG<br />
  342.       my $count = 0;<br />
  343.       <br />
  344.       my $Excel =
  345.       Win32::OLE->GetActiveObject('Excel.Application')<br />
  346.           ||
  347.       Win32::OLE->new('Excel.Application', 'Quit');  #
  348.       use the Excel application if it's open, otherwise open
  349.       new<br />
  350.       my $Book = $Excel->Workbooks->Open( $filename
  351.       );      # open the file<br />
  352.       foreach my $Sheet (in $Book->Sheets)
  353.       {                #
  354.       loop through all sheets<br />
  355.           foreach my $ChartObj (in
  356.       $Sheet->ChartObjects) {  # loop through all
  357.       chartobjects in the sheet<br />
  358.               my $savename
  359.       = "$filename." . $count++ . ".$filter";<br />
  360.               $ChartObj->Chart->Export({<br />
  361.  
  362.                   FileName    =>
  363.       $savename,<br />
  364.                   FilterName  =>
  365.       $filter,<br />
  366.                   Interactive =>
  367.       0});<br />
  368.           }<br />
  369.       }<br />
  370.       $Book->Close;</code></p>
  371.     </blockquote>
  372.     <a name="run_macro"></a>
  373.     <hr />
  374.  
  375.     <h1>How do I run a macro in Microsoft Excel?</h1>
  376.  
  377.     <p>Macros in Microsoft Excel can be run by using the
  378.     $Excel->Run method, for example:</p>
  379.  
  380.     <blockquote>
  381.       <p><code>$Excel->Run("PrintPDFFile");</code></p>
  382.     </blockquote>
  383.  
  384.     <p>In order to do this, you of course need to have a macro in
  385.     Excel that's called 'PrintPDFFile'...</p>
  386.     <a name="set_name_cell"></a>
  387.     <hr />
  388.  
  389.     <h1>How do I set the name of a cell in Microsoft Excel?</h1>
  390.  
  391.     <p>Use the Names->Add method on a sheet, giving it a name
  392.     and a range object to apply the name to, for example:</p>
  393.  
  394.     <blockquote>
  395.       <p><code>$Sheet->Names->Add({Name => 'NetCost',
  396.       RefersTo => $Sheet->Range('$B$10')});</code></p>
  397.     </blockquote>
  398.     <a name="create_new_folder"></a>
  399.     <hr />
  400.  
  401.     <h1>How do I create a new folder in Outlook?</h1>
  402.  
  403.     <p>Again, an example :-)</p>
  404.  
  405.     <blockquote>
  406.       <p><code>use strict;<br />
  407.       use Win32::OLE;<br />
  408.       use Win32::OLE::Const 'Microsoft Outlook';<br />
  409.       <br />
  410.       my $Outlook = Win32::OLE->new('Outlook.Application',
  411.       'Quit');<br />
  412.       my $ol = Win32::OLE::Const->Load($Outlook);<br />
  413.       <br />
  414.       my $namespace = $Outlook->GetNamespace("MAPI");<br />
  415.       my $Folder =
  416.       $namespace->GetDefaultFolder(olFolderInbox);<br />
  417.       my $NewFolder =
  418.       $Folder->Folders->Add("Test1");</code></p>
  419.     </blockquote>
  420.     <a name="use_ado"></a>
  421.     <hr />
  422.  
  423.     <h1>How do I use ADO?</h1>
  424.  
  425.     <p>In order to use ActiveX Data Objects (ADO) you can just</p>
  426.  
  427.     <blockquote>
  428.       <p><code>use strict;<br />
  429.       use Win32::OLE;<br />
  430.       use Win32::OLE::Const 'Microsoft ActiveX Data Objects';<br />
  431.       my $Conn = Win32::OLE->new('ADODB.Connection'); #
  432.       creates a connection object<br />
  433.       my $RS =
  434.       Win32::OLE->new('ADODB.Recordset');    #
  435.       creates a recordset object<br />
  436.       $Conn->Open('DBname');                          #
  437.       opens the database connection<br />
  438.       <br />
  439.       my $Fields = ['Id', 'Name', 'Phone'];<br />
  440.       my $Values = [1, 'Joe Doe', '555-1234'];<br />
  441.       $RS->AddNew($Fields,
  442.       $Values);                  #
  443.       adds a record<br />
  444.       <br />
  445.       print "This didn't go well: ", Win32::OLE->LastError(),
  446.       "\n";<br />
  447.           if
  448.       (Win32::OLE->LastError());<br />
  449.       <br />
  450.       $RS->Close;<br />
  451.       $Conn->Close;</code></p>
  452.     </blockquote>
  453.  
  454.     <p>To get further than this you should have a look at the ADO
  455.     FAQ at <a href= 
  456.     "http://www.fastnetltd.ndirect.co.uk/Perl/perl-win32-database.html">
  457.     http://www.fastnetltd.ndirect.co.uk/Perl/perl-win32-database.html</a>
  458.     or Jan Dubois article in TPJ#10 (visit The Perl Journal at <a
  459.     href="http://tpj.com/">http://tpj.com/</a>).</p>
  460.     <a name="use_notes"></a>
  461.     <hr />
  462.  
  463.     <h1>How do I use Lotus Notes?</h1>
  464.  
  465.     <p>Lotus Notes can be accessed through OLE, for example like
  466.     this:</p>
  467.  
  468.     <blockquote>
  469.       <p><code>use strict;<br />
  470.       use Win32::OLE;<br />
  471.       my $Notes = Win32::OLE->new('Notes.NotesSession')<br />
  472.           or die "Cannot start Lotus Notes
  473.       Session object.\n";<br />
  474.       my ($Version) = ($Notes->{NotesVersion} =~
  475.       /\s*(.*\S)\s*$/);<br />
  476.       print "The current user is $Notes->{UserName}.\n";<br />
  477.       print "Running Notes \"$Version\" on
  478.       \"$Notes->{Platform}\".\n";<br />
  479.       my $Database = $Notes->GetDatabase('', 'help4.nsf');<br />
  480.       my $AllDocuments = $Database->AllDocuments;<br />
  481.       my $Count = $AllDocuments->Count;<br />
  482.       print "There are $Count documents in the database.\n";<br />
  483.       for (my $Index = 1 ; $Index <= $Count ; ++$Index) {<br />
  484.           my $Document =
  485.       $AllDocuments->GetNthDocument($Index);<br />
  486.           printf "$Index. %s\n",
  487.       $Document->GetFirstItem('Subject')->{Text};<br />
  488.           my $Values =
  489.       $Document->GetItemValue('Index_Entries');<br />
  490.           foreach my $Value (@$Values) {<br />
  491.               print "
  492.       Index: $Value\n";<br />
  493.           }<br />
  494.           last unless $Index < 5;<br />
  495.       }</code></p>
  496.     </blockquote>
  497.  
  498.     <p>You can access all objects that are accessible to
  499.     LotusScript, and the LotusScript classes can be seen at <a
  500.     href="http://www.lotus.com/products/lotusscript.nsf">
  501.     http://www.lotus.com/products/lotusscript.nsf</a>. A good idea
  502.     would also be to read Jan Dubois article in TPJ#10 (visit The
  503.     Perl Journal at <a href="http://tpj.com/">
  504.     http://tpj.com/</a>)</p>
  505.     <a name="set_printer"></a>
  506.     <hr />
  507.  
  508.     <h1>How do I set the printer in Word?</h1>
  509.  
  510.     <p>The active printer can be set and retrieved through the word
  511.     application object with <code>$Word->{ActivePrinter} =
  512.     $printername</code>.</p>
  513.     <a name="convert_vba"></a>
  514.     <hr />
  515.  
  516.     <h1>How do I convert a VBA macro to Perl?</h1>
  517.  
  518.     <p>If you record a macro in Microsoft Office, this can often be
  519.     translated directly into Perl. In Visual Basic for Applications
  520.     (VBA) the syntax is like this:</p>
  521.  
  522.     <blockquote>
  523.       <p><code>object.method(argument).property = value</code></p>
  524.     </blockquote>
  525.  
  526.     <p>In Perl this becomes</p>
  527.  
  528.     <blockquote>
  529.       <p><code>object->method(argument)->{property} =
  530.       value;</code></p>
  531.     </blockquote>
  532.  
  533.     <p>So for example this code from VBA:</p>
  534.  
  535.     <blockquote>
  536.       <p><code>ActiveChart.Axes(xlCategory, xlPrimary).CategoryType
  537.       = xlCategoryScale</code></p>
  538.     </blockquote>
  539.  
  540.     <p>becomes this in Perl:</p>
  541.  
  542.     <blockquote>
  543.       <p><code>$Chart->Axes(xlCategory,
  544.       xlPrimary)->{CategoryType} = xlCategoryScale;</code></p>
  545.     </blockquote>
  546.     <a name="find_docs"></a>
  547.     <hr />
  548.  
  549.     <h1>Where do I find documentation for the object models?</h1>
  550.  
  551.     <p>The best way to learn about methods/properties would be
  552.     through an OLE type browser if the documentation is
  553.     unavailable.</p>
  554.  
  555.     <p>If you have Microsoft Excel or Microsoft Word available, go
  556.     into the Visual Basic Editor (Alt+F11). Now you can open the
  557.     object browser window (F2) and see what you find.</p>
  558.  
  559.     <p>There is also an OleView program (various names and
  560.     versions) included in Microsoft Visual C++ / Microsoft Visual
  561.     Studio if you don't have Office. Or you can download it from
  562.     the Microsoft COM website ( <a href= 
  563.     "http://www.microsoft.com/com/">
  564.     http://www.microsoft.com/com/</a>).</p>
  565.  
  566.     <p>But it is still possible that Notes doesn't reveal anything;
  567.     objects are not required to provide type info support. For
  568.     example Lotus Notes doesn't reveal nothing about it's internal
  569.     constants, methods and properties; you have to look them up in
  570.     the documentation.</p>
  571.  
  572.     <p>For Lotus Notes look at <a href= 
  573.     "http://www.lotus.com/products/lotusscript.nsf">
  574.     http://www.lotus.com/products/lotusscript.nsf</a>.</p>
  575.     <a name="find_constants"></a>
  576.     <hr />
  577.  
  578.     <h1>OK, but can I at least find the constants that are exported
  579.     from Win32::OLE::Const?</h1>
  580.  
  581.     <p>Yes, you can use the following code example to view all the
  582.     constants - you really shouldn't need this, but if you want to
  583.     know what's going on, it might help:</p>
  584.  
  585.     <blockquote>
  586.       <p><code>use strict;<br />
  587.       use Win32::OLE;<br />
  588.       use Win32::OLE::Const;<br />
  589.       <br />
  590.       my $xl = Win32::OLE::Const->Load("Microsoft Excel");<br />
  591.       printf "Excel type library contains %d constants:\n", scalar
  592.       keys %$xl;<br />
  593.       foreach my $Key (sort keys %$xl) {<br />
  594.           print "$Key =
  595.       $xl->{$Key}\n";<br />
  596.       }</code></p>
  597.     </blockquote>
  598.  
  599.     <p>Generally you should look at the documentation for
  600.     Win32::OLE::Const.</p>
  601.     <a name="errors"></a>
  602.     <hr />
  603.  
  604.     <h1>Why doesn't $! get set with the error message I am
  605.     generating?</h1>
  606.  
  607.     <p>Error messages from Win32::OLE doesn't go to the $!
  608.     variable, but can be accessed as <code>
  609.     Win32::OLE->LastError()</code></p>
  610.     <a name="odbc_ole"></a>
  611.     <hr />
  612.  
  613.     <h1>Why do I get an error when using ODBC and OLE?</h1>
  614.  
  615.     <p>For some reason you get an 'OleInitialize' error if you open
  616.     an OLE application first and then open an ODBC connection to
  617.     the Access ODBC driver. If you do it the other way around,
  618.     there is no problem with this.</p>
  619.  
  620.     <p>It looks like the Access ODBC driver calls OleInitialize().
  621.     This fails when Win32::OLE already initialized the COM
  622.     subsystem as "apartment threaded".</p>
  623.  
  624.     <p>In order to remove the error either start the ODBC driver
  625.     before the OLE application or, better yet, initialize the OLE
  626.     system with <code>
  627.     Win32::OLE->Initialize(Win32::OLE::COINIT_OLEINITIALIZE);</code></p>
  628.     <a name="strict"></a>
  629.     <hr />
  630.  
  631.     <h1>Why doesn't it work - even after all this?</h1>
  632.  
  633.     <p>Execute your scripts with <code>perl -w</code> and <code>use
  634.     strict</code> - this catches most of your errors. Apart from
  635.     this, read the documentation for Win32::OLE (a good start) and
  636.     possibly the documentation for the object you are trying to
  637.     use.</p>
  638.  
  639.     <p>In the case of Microsoft Office 97, make sure that you have
  640.     at least updated to Service Release 1 - much of the OLE in
  641.     Microsoft Office 97 is broken without this update.</p>
  642.     <br />
  643.     <hr />
  644.  
  645.     <h1><a name="AUTHOR_AND_COPYRIGHT">AUTHOR AND
  646.     COPYRIGHT</a></h1>
  647.  
  648.     <p>This <font size="-1">FAQ</font> was compiled by Henning
  649.     Michael Møller-Nielsen of RTO based on examples by many
  650.     people, especially Jan Dubois. It is maintained by Henning
  651.     Michael Møller-Nielsen, Philip Martin, Kevin Meltzer and
  652.     Eric Smith at <a href="mailto:perlwin32faq@rto.dk">
  653.     perlwin32faq@rto.dk</a>.</p>
  654.  
  655.     <p>This <font size="-1">FAQ</font> is in the public domain. If
  656.     you use it, however, please ensure that you give credit to the
  657.     original authors.</p>
  658.  
  659.     <p><!-- beginning of leaf footer--></p>
  660.  
  661.     <table width="100%">
  662.       <tr>
  663.         <td bgcolor="000000" width="70" height="31"><a href= 
  664.         "http://www.activestate.com/"><img src="ASbutton.gif" alt= 
  665.         "ActiveState Home Page" border="0" width="68" height=
  666.         "30" /></a></td>
  667.  
  668.         <td width="10"> </td>
  669.  
  670.         <td valign="middle" bgcolor="#cc0066"><font face=
  671.         "sans-serif" size="+1" color="#ff99cc">   
  672.         Win32 FAQ</font></td>
  673.       </tr>
  674.     </table>
  675.     <!-- end  of leaf footer-->
  676.   </body>
  677. </html>
  678.  
  679.