Dear Monks, Here is an interesting one for you. I'm sure I am missing something obvious. I am working with a cgi form document. One of the form questions the client fills out, allows multiple selections. For instance,
Test1,
Test2,
Test3,
Test4,
The CGI program then takes those multiple selections, uses the split function @rename_file = split(/,/, $in{'clients'}); splits the data on the comma and then stores each selection into the array rename_file. From there, the program runs a foreach loop, opens up a Microsoft Word file called CENTRAL NJ.doc, replaces text in that word file with the name of the choice the client selected, saves the file according to the file name the client chose, closes the document and then repeats this whole process until all of the clients selections are used.
See code below:
foreach $file (@rename_file)
{
my $word = Win32::OLE->new('Word.Application', 'Quit');
$word->Documents->Open("S:/Documents/CENTRAL NJ.doc") || die("Unable to open document ", Win32::OLE->LastError());
$word->Selection->Find->{'Text'}='CENTRAL NJ';
$word->Selection->Find->Replacement->{'Text'}="$file";
$word->Selection->Find->Execute({Replace=>wdReplaceAll});
$word->ActiveDocument->SaveAs({FileName=>"S:/Documents/$file.doc"});
$word->ActiveDocument->Close;
$word->Quit;
}
If the client just selects one choice, the program works fine. The problem is if a client selects more than one option on the cgi form, the program fails to work. For example, if the client selects Test1 and Test2, the program works fine with Test1 (opens up CENTRAL NJ.doc, replaces the text inside the document "CENTRAL NJ" with "Test1", saves the file as Test1, closes the document) but then when it gets to Test2, the original word file "CENTRAL NJ.doc" loses the text inside the document "CENTRAL NJ" and then the program stops working. Any answers as to why this happens?

In reply to Question On Forms and MS Word by njweatherman

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.