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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |