in reply to Testing for Excel hyperlinks with Win32::OLE
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 ...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
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();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Testing for Excel hyperlinks with Win32::OLE
by Albannach (Monsignor) on Sep 27, 2005 at 17:32 UTC | |
by davidrw (Prior) on Sep 27, 2005 at 18:07 UTC | |
by sz (Friar) on Sep 27, 2005 at 19:53 UTC |