Instead of using Find (like ++poj suggested), you could also iterate thru all the Item()s in the Hyperlinks() collection. Instead of deleting each hyperlink and adding a new one, you could just edit the existing one. (If necessary, it would be easy to add in decision logic on each hyperlink.)

use warnings; use strict; use Win32::OLE; use Data::Dumper; $Data::Dumper::Maxdepth = 2; my $MSWord = Win32::OLE->new('Word.Application', 'Quit') or die $!; $MSWord->{Visible} = 1; my $doc = $MSWord->Documents->Open('C:/temp/hyper.docm'); local $, = "\t"; my $url = 'http://www.perlmonks.org/'; my $HLs = $doc->Hyperlinks(); foreach my $ihl ( 1 .. $HLs->Count ) { # ->Item() is 1-based, not 0-b +ased print STDERR $ihl, $HLs->Item($ihl), @{ $HLs->Item($ihl) }{'TextTo +Display', 'Address', 'SubAddress'}; @{ $HLs->Item($ihl) }{'Address', 'SubAddress'} = ($url, ''); print STDERR $ihl, $HLs->Item($ihl), @{ $HLs->Item($ihl) }{'TextTo +Display', 'Address', 'SubAddress'}; } $doc->Save; $doc->Close;

There may not be much on the web for how to do MS Word OLE thru perl, but since the OLE uses the same API as Word's embedded VBA, I just searched for "word vba search for hyperlink", where I found this stackoverflow answer, or "word vba edit hyperlinks", resulting in this answer, and looked at the MSDN documentation for the Hyperlinks collection and Hyperlink object


In reply to Re: M$ Word ole hyperlink by pryrt
in thread M$ Word ole hyperlink by 3dbc

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.