C++ Excel automate, add hyperlink

R

Rui Oliveira

C++ Excel automate, add hyperlink

How can I add a hyperlink in excel automation?

We have function “Hyperlink.Addâ€, but I don’t know what insert in first
argument.

LPDISPATCH Add(LPDISPATCH Anchor, LPCTSTR Address, const VARIANT&
SubAddress, const VARIANT& ScreenTip, const VARIANT& TextToDisplay);

Anyone have some sample code?

Thanks,
Rui
 
B

Birgit

Hi Rui,

Here is what I used recently from VBA

Set myHyperlink =
ActiveWorkbook.Worksheets("Inhoudsopgave").Hyperlinks.Add(Anchor:=myrange.Offset(i,
1).Range("A1"), Address:="", SubAddress:="'" & Worksheets(i).Name & "'!A1")
myHyperlink.TextToDisplay = "my Text here"

the argument anchor is a range (in my case I insert a number of hyperlinks
in a loop).
Sorry, this is no C++ but I'm sure you'll manage a LPDISPATCH to a
range-object.

The VBA-help of excel is an excellent source of information to the excel
object. There is very little C++ info around.

HTH,
Birgit
 
R

Rui Oliveira

In vb I have the code. Thanks anyway.

In C++ I am trying something like:

icl_hyperlinks.Add(icl_oWksSheet.GetRange(COleVariant("A2"),
COleVariant("A2")), "c:\\test.txt", covOptional, covOptional,
COleVariant("test"));

But this way don't write any hyperlink.
 
R

Rui Oliveira

I forgotten the GetHyperlinks


CString ls_cellPos;
ls_cellPos.Format("A%d", 3);
icl_hyperlinks = icl_oWksSheet.GetHyperlinks();
icl_hyperlinks.Add(icl_oWksSheet.GetRange(COleVariant(ls_cellPos),
COleVariant(ls_cellPos)), "c:\\test.txt", covOptional, covOptional,
COleVariant("test"));

Tks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top