0
votes

I have workbookA, I run a macro which copy information from workbookA to workbookB. I want to add a hyperlink for every row (so I can find where this row is in workbookA). But I can't get it to work. In the same workbook but different sheets it works.

My code:

Set rw = sh.rows(i)
Set targetCell = rw.Cells(1, "R")
wbB.Sheets("Sheet1").Hyperlinks.add Anchor:=rng.EntireRow.Cells(1, "A"), Address:="", SubAddress:="='" & sh.name & "'!" & targetCell.Address & "", TextToDisplay:="Link"

Tx!

1

1 Answers

2
votes

To use the hyperlink to open a different workbook, you should do something like:

wbB.Sheets("Sheet1").Cells(10, 1).Hyperlinks.Add Anchor:=wbB.Sheets("Sheet1").Cells(10, 1), Address:="Your.xlsm", SubAddress:="Sheet1!A10", TextToDisplay:="Link"

Where your Anchor is where the link should be placed in your worksheet, address is the name of your workbook to be opened and SubAddress is the Sheet and range that should be selected when opened.