First question is: what are you trying to do? At first, you're describing a copy (from Excel) and paste (into Word) while maintaining formatting. But then you're using something called 'LinkedToExcel', which sounds like something totally different. In Word, you can "link" to an Excel file, which is totally different than the copy and paste that you say that you wanted to.

When trying to write Perl code to control Office products via Win32::OLE, one of the best methods for figuring out code is to record a macro to do the desired task(s) and then work to convert the source code of that macro into Perl. You can find more details at Use The Macro Recorder, Luke (Re: Using Win32::OLE and Excel - Tips and Tricks) and other nodes if you do some more searching. Basically using this macro technique and using the Office OLE documentation is what I have used to create my scripts that automate Excel.

Out of curiosity, I just tried the micro technique on my computer that has Office 2010. The paste method used was specifying that I was pasting an OLE object and it did maintain the formatting that was used in Excel. Looking at the macro source code, there was no 'LinkedToExcel' anywhere.

I haven't written Perl code to automate Office products in quite a while so my VB to Perl conversion skills are quite rusty right now. Below is the source code of the macro that I recorded. Thought I'd share it so that you (and/or others) can convert that into Perl. (If I find time this weekend, I may try to shake off the rust to see if I can correctly convert that code into Perl.)

Sub Macro1() ' ' Macro1 Macro ' ' Selection.PasteSpecial Link:=False, DataType:=wdPasteOLEObject, Pl +acement _ :=wdInLine, DisplayAsIcon:=False End Sub

One last thing. The macro source code above utilizes VB's 'selection'. I'd recommend not trying to use that in your Perl code. See Excel’s Select and Activate considered harmful for more details from someone who is far more knowledgeable than me on this topic.


In reply to Re: Trying to use Win32::OLE PasteExcelTable method by dasgar
in thread Trying to use Win32::OLE PasteExcelTable method by aaronbaum2000

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.