Excel VBA-.hyperlink无法应用于范围

时间:2019-02-20 15:15:57

标签: excel vba hyperlink

因此,要使此工作正常,我很难受...

AIM :单击“ UpdateSheets”,复制“ ServerTemplate”,并将E列中的名称用作工作表名称,完成后,将E列中的单元格超链接到相应的工作表。

问题:对于E列中的所有单元格,超链接仅链接到名称为E列中最后一个填充单元格的工作表;还将E10更改为与E列中最后一个填充的单元格相同的值

问题:有人可以帮忙让我知道我要去哪里了吗?

Private Sub UpdateSheets_Click()

Dim wsMASTER As Worksheet, wsTEMP As Worksheet, wsGENERAL As Worksheet
Dim wasVISIBLE As Boolean
Dim shNAMES As Range, Nm As Range

With ThisWorkbook

Set wsTEMP = .Sheets("ServerTemplate")
Set wsMASTER = .Sheets("Main")
Set shNAMES = wsMASTER.Range("E10:E" & Rows.Count).SpecialCells(xlConstants)

    wasVISIBLE = (wsTEMP.Visible = xlSheetVisible)
    If Not wasVISIBLE Then wsTEMP.Visible = xlSheetVisible

Application.ScreenUpdating = False
For Each Nm In shNAMES
    If Not Evaluate("ISREF('" & CStr(Nm.Text) & "'!A1)") Then
        wsTEMP.Copy After:=.Sheets(.Sheets.Count)
        ActiveSheet.Name = CStr(Nm.Text)
    End If
    wsMASTER.Hyperlinks.Add anchor:=shNAMES, Address:="", _
    SubAddress:=CStr(Nm.Text) & "!A1", _
    TextToDisplay:=Nm.Text
Next Nm
wsMASTER.Activate
    If wasVISIBLE Then wsTEMP.Visible = xlSheetHidden Else: If Not wasVISIBLE Then wsTEMP.Visible = xlSheetHidden
    Application.ScreenUpdating = True
For Each wsGENERAL In ThisWorkbook.Worksheets
    If wsGENERAL.Name = "ServerTemplate(1)" Then
        wsGENERAL.Delete
    End If
Next wsGENERAL
End With
MsgBox "All servers have been added."
ThisWorkbook.Save
End Sub

0 个答案:

没有答案