in reply to M$ Word ole hyperlink
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: M$ Word ole hyperlink
by 3dbc (Monk) on Jan 31, 2017 at 18:00 UTC | |
by poj (Abbot) on Jan 31, 2017 at 18:15 UTC | |
by pryrt (Abbot) on Jan 31, 2017 at 19:20 UTC | |
by 3dbc (Monk) on Jan 31, 2017 at 22:34 UTC | |
by pryrt (Abbot) on Jan 31, 2017 at 23:22 UTC | |
by 3dbc (Monk) on Feb 01, 2017 at 18:02 UTC | |
|