For worst-case, your solution doesn't seem too bad .. Might be able to find a better way by poking around with recording a macro and seeing what code comes out ... For example, I just made this (actions i took are in comments):
Sub Macro1() ' Right-click a cell Range("C10").Select ' From the context menu, click "Hyperlink...", and in there fill in th +e dialog ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _ "http://blah.example.com", TextToDisplay:="foo" Range("C10").Select ' Right-click cell again, do "Edit Hyperlink..." and s/foo/bar/ Selection.Hyperlinks(1).TextToDisplay = "bar" End Sub
But what's of interest here is it seems that Excel keeps track of all the hyperlinks in the ActiveSheet.Hyperlinks collection, so you could hash that up on it's Anchor property so you know what cells all of the hyperlinks are in ...
Update: I was able to access that collection, but i can't seem to get the Anchor property from it..
use strict; use warnings; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; use Win32::OLE::Variant; use Win32::OLE::NLS qw(:LOCALE :DATE); $Win32::OLE::Warn = 3; # Die on Errors. my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); my $Book = $Excel->Workbooks->Open('C:\Documents and Settings\David\hy +perlinks.xls'); my $Sheet = $Book->Worksheets("Sheet1"); $Sheet->Activate(); foreach ( 1.. $Sheet->Hyperlinks->Count() ){ print "\n"; warn $Sheet->Hyperlinks($_)->TextToDisplay; warn $Sheet->Hyperlinks($_)->Address; # warn $Sheet->Hyperlinks($_)->Anchor; # This errors with "Member no +t found" } $Book = $Excel->Workbooks->Close();

In reply to Re: Testing for Excel hyperlinks with Win32::OLE by davidrw
in thread Testing for Excel hyperlinks with Win32::OLE by sz

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.