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

I want to add a Hyperlink to a MS Word Document using Win32::OLE The Hyperlink needs the Address and a corresponding Text to Display. Could someone please help me with that?
  • Comment on Adding Hyperlink to a MS Word Document using Win32:OLE

Replies are listed 'Best First'.
Re: Adding Hyperlink to a MS Word Document using Win32:OLE
by marto (Cardinal) on Feb 03, 2006 at 16:08 UTC
    Hi roshmont,

    I have written a short example to get you started:
    #!/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" });

    Hope this helps.

    Martin
      Martin, Thanks so much. Would you know how to define the range for the Hyperlink such that I can insert the Hyperlink at the current selection position.i.e after I have finished writing some text to the document?