最近,我尝试为Excel工作簿创建一个新的宏,用户可以在其中输入需要添加超链接的单元格范围,其中每个单元格都具有图像的值/名称
Sub RelinkImage()
Dim xStr As String
Dim xRange As Range
Dim xCell As Range
Dim xAddress As String
On Error Resume Next
xAddress = Application.ActiveWindow.RangeSelection.Address
Set xRange = Application.InputBox("Please select a range", , xAddress, , , , , 8)
Application.ScreenUpdating = False
For Each xCell In xRange
xStr = xCell.Value
xCell.Hyperlinks.Add Address:="C:\EnQuest Anomalies Documents\Images\" + xStr + ".png", TextToDisplay:=xStr
xCell.Font.Size = 10
Next
Application.ScreenUpdating = True
MsgBox "C:\EnQuest Anomalies Documents\Images\" + xStr + ".png"
End Sub
但是,即使MsgBox仍显示正确的链接,代码也不会放置任何超链接。
即使我尝试从每个单元格获取xCell.value,我也需要将xCell声明为超链接吗?
是否需要做任何修改才能实现这一目标?
答案 0 :(得分:0)
需要添加Anchor:=xCell,
在Address:=
之前