我不是真的进入高级VBA,只是一些基础知识,我需要一个查看activecell内容的代码,然后搜索工作表名称,然后将activecell连接到与activecell内容同名的相关表单,通过超链接。如果你们能帮助我,我会非常感激。 提前致谢! P.S:我在帖子中搜索但找不到任何答案:/
最终正确的代码
Sub MakeHyperlink()
Dim i As Long
For i = 1 To Sheets.Count
If ActiveCell.Value = Sheets(i).Name Then
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:="'" & _
Sheets(i).Name & "'" & "!A1", TextToDisplay:=ActiveCell.Value
End If
Next i
ActiveCell.HorizontalAlignment = xlCenter
End Sub
答案 0 :(得分:0)
Sub LinkUPsheets()
For Each sht In Worksheets
For Each lnk In Range("A1:A10")
If lnk.Value = sht.Name Then
lnk.Select
ActiveSheet.Hyperlinks.Add _
Anchor:=Selection, _
Address:="", _
SubAddress:=sht.Name & "!A1", _
TextToDisplay:=lnk.Text
End If
Next
Next
End Sub
答案 1 :(得分:0)
试试这个:
Sub Macro5()
Dim i, j, lastrow As Long
lastrow = ActiveSheet.Range("D1").End(xlDown).Row
For j = 1 To lastrow
For i = 1 To Sheets.Count
Cells(j, 4).Select
If Sheets(i).Name = Cells(j, 4).Value Then
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
Sheets(i).Name & "!A1", TextToDisplay:=Cells(j, 4).Value
End If
Next
Next
End Sub