Excel中的macros超链接

我有这个代码,将单元格更改为超链接。 我想要使​​用超链接中的单元格的值

Sub HyperAdd() 'Converts each text hyperlink selected into a working hyperlink For Each xCell In Selection ActiveSheet.Hyperlinks.Add Anchor:=xCell, _ Address:="http://example.ie/booking/viewBooking/=xCell" Next xCell End Sub 

如果单元格的值是123,我如何使锚链接这个urlhttp://example.ie/booking/viewBooking/123

正如Fadi所指出的那样,这个问题的答案是语法修正。

更改:

 Address:="http://example.ie/booking/viewBooking/=xCell" 

成为:

 Address:="http://example.ie/booking/viewBooking/" & xCell 


Excel将引号内的字符视为string,因此在“http …”string中完全引用“xCell”不起作用。 每次只会导致地址为“ http://example.ie/booking/viewBooking/=xCell ”,因为Excel不会将string中的variables名称视为variables。

相反,string需要如上所示添加,以便在string外部使用xCell,并使用xCell的值而不是文本“xCell”。

那么,如果xCell的值是“abc123”,那么

 Address:="http://example.ie/booking/viewBooking/" & xCell 

将会:

 Address:="http://example.ie/booking/viewBooking/" & "abc123" 

这变成:

 Address:="http://example.ie/booking/viewBooking/abc123"