Hello all, Here is what I seek: My Perl reads an input file with about 80 rows of data. For each row I need to create a new DOCX with some of the data from that input row. All MS-WORD files go the same folder. I spent a couple of days trying to figure this out but couldn't. Please, could any of you provide me with a simple example of a very simple Perl pgm that automatically creates 2 docx files, enters in them a constant and a variable from the input file, and saves them, without the user's intervention. I can't save the docx files. I get error: "Can't call method "SaveAs" on an undefined value at DOC.pl line 18, <INPUTFILE> line 1."

use strict; use warnings; use Win32::OLE; use Win32::OLE::Const 'Microsoft Word'; my $path = 'E:/MASAV/DOC/'; my $input = 'input.txt'; my $in_file = $path . $input; my $counter = 4534; my $My_Word = Win32::OLE->new('Word.Application') or die "Problem with MS-WORD"; open (INPUTFILE, "<$in_file")|| die "Can not open $in_file\n"; while(<INPUTFILE>) { chomp $_; $counter++; my $docx_name = $counter.".docx"; $My_Word->{'Visible'} = 0; $My_Word->{DisplayAlerts} = 0; my $My_Save = $My_Word->ActiveDocument->SaveAs( {FileName => $docx_name, FileFormat => wdFormatDocument}); $My_Word->{ActiveDocument}->Close; } $My_Word->Quit;

In reply to create .docx files (MS-WORD with WIN32::OLE) by gadi99

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.