As I said earlier in the thread, I don't really know Word. However, there are some issues I know about in Excel that may transfer to Word. When opening a second instance of Excel manually, it usually asks me about read only copies of files like personal.xls, which contains macros I want always available. However, it doesn't do this when I open it from Perl. You may find setting the DisplayAlerts (if there is an analogue in Word) property to False may help, or it may just be the way I have my computer configured. If so, it's a function of something I don't know about.

The code below works for me, without caring about the Word file being open. It also closes Word when the Perl exits, but not the new instance of Excel. Clearly, you can't save the Excel file if a file of that name is currently open. Also, there's some strange trailing character that gets copied across. I haven't tried chomping it - that's not in the question in the exam paper I read :-).
use strict; use warnings; use diagnostics; use Win32::OLE; my $xl = Win32::OLE->new('Excel.Application'); $xl->{Visible} = 1; my $wb = $xl->Workbooks->Add; my $word = Win32::OLE->new('Word.Application'); my $doc = $word->Documents->Open({FileName => "C:\\Perl\\eg\\842813\\W +ord.doc", ReadOnly => 1}); my $row=0; my $col=1; for (1..$doc->Paragraphs->Count) { $row++; $wb->Sheets(1)->Cells($row, $col)->{Value} = $doc->Paragraphs($_)- +>Range->Text; }
Regards,

John Davies

In reply to Re: Windows; If (2003) MS Word or Excel are already executing? by davies
in thread Windows; If (2003) MS Word or Excel are already executing? by gibsonca

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.