我的代码不起作用,我正在尝试通过单击超链接插入一行,并且我正在使用 + 符号的超链接...
ActiveSheet.Cells(1, 1).Value = "+"
If ActiveSheet.Cells(1, 1) <> "" Then
ActiveSheet.Hyperlinks.Add Anchor:=Cells(1, 1), _
Address:=strString
End If
这本练习册......
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
If Target.Parent.Value = "+" Then Rows(Target.Parent.Row + 1).Insert
End Sub
答案1
Hyperlinks(1).Parent
作为范围
Hyperlinks(1).Parent.Parent
作为工作表
所以你的代码应该是:
With ActiveSheet
.Cells(1, 1).Value = "+"
'''No need to test as you fill it yourself
.Hyperlinks.Add Anchor:=.Cells(1, 1), Address:=strString
End If
Sheet 的模块:
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
If Target.Parent.Value = "+" Then _
Target.Parent.Parent.Rows(Target.Parent.Row + 1).Insert CopyOrigin:=xlFormatFromRightOrBelow
End Sub
或更短:
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
If Target.Parent.Value = "+" Then _
Me.Rows(Target.Parent.Row + 1).Insert CopyOrigin:=xlFormatFromRightOrBelow
End Sub
我添加了CopyOrigin
参数,从下面一行复制格式,以避免在新插入的行上重现超链接样式!
CopyOrigin
采取以下任一参数:
Const xlFormatFromLeftOrAbove = 0
Member of Excel.XlInsertFormatOrigin
和
Const xlFormatFromRightOrBelow = 1
Member of Excel.XlInsertFormatOrigin