Excel Hyperlinks

Add-in Express™ Support Service
That's what is more important than anything else

Excel Hyperlinks
 
massimob




Posts: 2
Joined: 2009-12-03
Hi, it's possible to have an example of code that show how to add an hyperlink to a named range in a users selected cell?

- Massimo
Posted 17 Jun, 2021 09:26:38 Top
Andrei Smolin


Add-in Express team


Posts: 18218
Joined: 2006-05-11
Hello Massimo,

Sorry for not responding in time to your email and thus making you ask this question here; I was testing this code:

function TAddInModule.GetSelectedRange(): Excel2000.ExcelRange;
var Intf: IDispatch;
begin
  Intf :=  ExcelApp.Selection[adxLCID];
  Intf.QueryInterface(Excel2000.DIID_ExcelRange, Result);
end;

procedure TAddInModule.adxRibbonTab1Controls0Controls0Click(Sender: TObject;
  const RibbonControl: IRibbonControl);
var
  rng: Excel2000.ExcelRange;
  j: integer;
begin
 rng := GetSelectedRange;
 rng.Hyperlinks.Add(rng, 'http://www.google.com', EmptyParam, EmptyParam, EmptyParam);
end;


Note that you need to add a condition as rng can be nil if you select anything but range (e.g. shape).

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 17 Jun, 2021 10:42:41 Top
massimob




Posts: 2
Joined: 2009-12-03
Many thanks Andrei! It works fine!
Wasn't my intention to push, I thought afterwards that would be better to post on the forum instead.

I was putting EmptyParam in the second parameter instead ''

rng.Hyperlinks.Add(rng, '', '_localname', EmptyParam, 'test link');




-
Massimo
Posted 17 Jun, 2021 14:28:42 Top
Andrei Smolin


Add-in Express team


Posts: 18218
Joined: 2006-05-11
No problem! And many thanks!

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 18 Jun, 2021 03:01:19 Top