Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Dear Monks,
I am Not good in VBA, and I would like to convert a VBA Macro to Perl. After reading few help pages from ActivePerl site. I wrote a Perl code. Now it is giving following error
Can't modify non-lvalue subroutine call at rapid.pl line 16.
My VBA Macro goes as follows
VBA Macro
Selection.HomeKey wdStory Selection.Text = "This is the inserted text 1" Selection.Collapse wdCollapseEnd Selection.TypeParagraph Selection.Text = "This is the inserted text 2" Selection.Collapse wdCollapseEnd Selection.TypeParagraph
and my Perl script goes as follows.
Perl Script
use strict; use warnings; use Win32::OLE; use Win32::OLE::Const 'Microsoft Word'; use Cwd; my ($file) = @ARGV; my $cwd_path = getcwd(); $cwd_path=~ s/\//\\/gs; my $file_name = "$cwd_path\\$file"; my $Word = Win32::OLE->new('Word.Application'); $Word->{'Visible'} = 1; $Word->Documents->Open($file_name) || die("Unable to open document", W +in32::OLE->LastError());; $Word->Selection->HomeKey (wdStory); $Word->Selection->Text="This is the inserted text"; $Word->Selection->Collapse (wdCollapseEnd); $Word->Selection->TypeParagraph; $Word->Selection->Text("This is the inserted text 2"); $Word->Selection->Collapse (wdCollapseEnd); $Word->Selection->TypeParagraph; $Word->Documents($file_name)->Save(); $Word->Quit();
I searched from 'SuperSearch' but could Not receive satisfactory information. I would be grateful, if somebody could guide me on this. I don't expect straightforward solutions but if you could direct me to any good tutorials on this topic, I would be grateful to you.
Regards,
Sandeep
Update
Dear All,
Thanks to all for your support. It was my lack of knowledge that I was using "Text" instead of "TypeText". Thanks to marto for providing this hint.

In reply to VBA to Perl by sanPerl

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (8)
    As of 2019-10-18 18:31 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Notices?