利用VBA批量给Excel添加超链接

主要思想是先给单元格设置名称,再设置超链接

代码如下:

Sub creat_link()


Dim Source As String
Source = "t1"
Dim Target As String
Target = "t2"
Dim i As Integer
i = 1
Dim j As Integer
j = 1
    
Do While i < 10

    Dim Svalue As String
    Svalue = Sheets(Source).Cells(i, 1)
        
    If (Svalue = "11") Then
        
        Do
            Dim Tvalue As String
            Tvalue = Sheets(Target).Cells(j, 1)
            
            If (Tvalue = "aa") Then
            
                '创建超链接的关键语句
                Sheets(Target).Cells(j, 1).Name = Tvalue
                ActiveSheet.Hyperlinks.Add Anchor:=Sheets(Source).Cells(i, 1), Address:="", SubAddress:=Tvalue
                
            End If
            
            j = j + 1
            
        Loop While j < 10
        
    End If
    
    i = i + 1

Loop


End Sub
原文地址:https://www.cnblogs.com/wanggs/p/5039737.html