Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Win32::Ole selection

by c-era (Curate)
on Dec 11, 2001 at 00:48 UTC ( #130771=note: print w/ replies, xml ) Need Help??


in reply to Win32::Ole selection

I'm not sure exactly how you want to select the text, but here is one way:

use Win32::OLE; use Win32::OLE::Const 'Microsoft Word'; my $word = Win32::OLE->new('Word.Application'); $word->{Visible} = 1; my $document=$word->Documents->Add; $word->Selection->TypeText("Some Text"); $word->Selection->HomeKey(wdLine); $word->Selection->EndKey(wdLine, wdExtend)
P.S. You can easily findout what you need to do by using word's record macro feature.


Comment on Re: Win32::Ole selection
Download Code
Re: Re: Win32::Ole selection
by dws (Chancellor) on Dec 11, 2001 at 01:28 UTC
    A more targeted way of doing this (which allows for inserting and selecting text at arbitrary locations in the file) is:
    use Win32::OLE; use Win32::OLE::Const 'Microsoft Word'; my $str = "Some Text"; my $word = Win32::OLE->new('Word.Application'); $word->{Visible} = 1; my $document=$word->Documents->Add; $word->Selection->TypeText($str); $word->Selection->MoveLeft(wdCharacter, length $str, wdExtend);
Re: Re: Win32::Ole selection
by Bloodelf (Beadle) on Dec 11, 2001 at 01:42 UTC
    That way would work, but what I'm trying to do is select a known line on the document. In VBA, a command like  ActiveDocument.Paragraphs(1).range can be used to select a specific line on the document (in this case the 1st) but I can't seem to be able to convert this command ....
    Thanks anyway.
      Solved it!
      use Win32::OLE; my $word = Win32::OLE->new('Word.Application'); $word->{Visible} = 1; my $document=$word->Documents->Add; $word->Selection->TypeText("Some Text"); $word->Selection->Paragraphs("1"); $document->Select->ActiveDocument->Paragraphs(1)->range;
      Cheers.
        correction.....
        use Win32::OLE; my $word = Win32::OLE->new('Word.Application'); $word->{Visible} = 1; my $document=$word->Documents->Add; $word->Selection->TypeText("Some Text"); $word->ActiveDocument->Paragraphs(1)->range->Select;
        (...Doh!)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://130771]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2014-12-28 16:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (182 votes), past polls