roshmont has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to insert a HyperLink into a MS Word Document using Win32::OLE. I have the following fragment of the code pasted below. However this inserts the HyperLink at the starting of the Document.I want to add the Hyperlink after $selection->TypeText("Click here"); I tried several ways to set the Range.But was not successful. Thanks in advance.
#!/usr/bin/perl use strict; use warnings; use Win32::OLE; my $word = Win32::OLE->new('Word.Application') or die $!; $word->{'Visible'} = 1; my $document = $word->Documents->Add; my $selection = $word->Selection; $selection->TypeText("Click here"); my $range = $word->ActiveDocument->Content; $document->Hyperlinks->Add({ Anchor => $range, Address => "http://www.perlmonks.org" });

Replies are listed 'Best First'.
Re: Setting Range using Win32:OLE
by chargrill (Parson) on Feb 03, 2006 at 22:10 UTC

    That looks pretty similar to this node: Adding Hyperlink to a MS Word Document using Win32:OLE

    You don't get better answers when you ask the same questions multiple times...



    --chargrill
    $/ = q#(\w)# ; sub sig { print scalar reverse join ' ', @_ } + sig map { s$\$/\$/$\$2\$1$g && $_ } split( ' ', ",erckha rlPe erthnoa stJu +" );
Re: Setting Range using Win32:OLE
by traveler (Parson) on Feb 03, 2006 at 22:59 UTC
    chargrill is right, but try this
    use strict; use warnings; use Win32::OLE; my $word = Win32::OLE->new('Word.Application') or die $!; $word->{'Visible'} = 1; my $document = $word->Documents->Add; my $selection = $word->Selection; $selection->TypeText("Please click here now"); my $range = $document->content; my $search = $range->Find; $search->{Text} = "here"; my $link = $search->Execute(); print $link ? "yes\n":"no\n"; #just so you can see $document->Hyperlinks->Add({ Anchor => $range, Address => "http://www.perlmonks.org" });
      Thanks a ton guys.That was really useful.Also apologize for having started a new thread.