Finally something that brings me closer to my goal....Can anyone help?

I am attempting to move through a directory, pull out only files of a .fin extension (which is Word document format), save each one as .rtf (Rich Text Format). I'd also like to be able to run some predefined macros on the files, but I thought just being able to save was a good place to start.

Currently I get an error stating 'Can't call method "SaveAs" on an undefined value'. If someone could point me to some clearer text on Win32::OLE than the stuff that ASPN, CPAN and Oreilly's Win32 or Nutshell book I'd greatly appreciate it. If you could tell me what stupid thing I am missing this time that would be great too.

Here's the code:

#usr/bin/perl use Win32::OLE; use Win32::OLE::Const 'Microsoft Word'; $articleDirName = "c:\\work\\test\\psq\\test\\"; unless (opendir(DIR, $articleDirName)) { warn "Can't open $articleDirName\n"; closedir(DIR); exit(1); } foreach (readdir(DIR)) { next if $_ eq '.' || $_ eq '..'; $path = "$articleDirName$_"; if (-f $path){ if ($path =~ /\.fin/i){ $doc = Win32::OLE->GetObject($path); $fileName = $path . ".rtf"; print "$fileName\n"; $doc->ActiveDocument->SaveAs({FileName => $fileName, FileFo +rmat => wdFormatRTF}) } undef $doc; undef $path; undef $fileName; } }

In reply to Re: MSWord OLE, font and saveas Problems by Anonymous Monk
in thread MSWord OLE, font and saveas Problems by traveler

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.