title: How to modify the column widths of a Word table using Perl?
body: <p>Using Perl with the Win32::OLE module I am attemping to insert a table into a Microsoft Word document and then modify the column widths. I can insert a table without any trouble, but modifying the column widths is proving more difficult. After creating a macro and trying to translate the VBA into Perl, here is what I have:</p>
  
  <pre><code>my $word = Win32::OLE-&gt;new('Word.Application', sub {$_[0]-&gt;Quit;});
  my $doc = $word-&gt;Documents-&gt;Open('myfile.doc');
  
  ### Code to find and select a tag to replace with a table goes here ###
  
  my $table = $doc-&gt;Tables-&gt;Add($word-&gt;Selection-&gt;Range, 4, 4);
  $table-&gt;Columns(1)-&gt;{PreferredWidthType} = wdPreferredWidthPoints;
  $table-&gt;Columns(1)-&gt;{PreferredWidth} = 200;
  </code></pre>
  
  <p>Unfortunately this gives a "Can't use an undefined value as a HASH reference" error on the final two lines. I've tried several other variations on this but none have worked, and Google hasn't helped either. I'd really appreciate an answer as to how to do this.</p>
  
  <p>Thanks.</p>