【问题标题】:Excel VBA code for hyperlink to other sheets用于超链接到其他工作表的 Excel VBA 代码
【发布时间】:2016-08-31 04:31:12
【问题描述】:

我正在编写的工作簿用于项目跟踪。在打开页面上,它是当前和即将进行的项目页面。当您按下表单控制按钮时,它会执行下面的代码。下面的代码所做的是阅读工作簿中的每张纸(有 30 张纸),然后是 A5 中所有值为“Project #:”的工作表。当它具有该值时,它将指定值放入指定的行和列。开头有“**”的那一行是行不通的。它下面带“*”的行是我暂时使用的,但它没有超链接,只有工作表名称。

我希望在下面的代码中发生的事情是使“A”行包含工作表名称作为文本和指向该工作表的超链接

 For Each ws In ThisWorkbook.Worksheets
            If ws.Range("A5") = "Project # :" And ws.Range("E16") = "" Then
                x = .Range("B" & Rows.Count).End(xlUp).Offset(1).row

                **.Cells(x, "A").Formula = "=ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _'" & ws.Name & "'"
                *.Cells(x, "A").Value = ws.Name    'classifying number

                .Cells(x, "B").Formula = "='" & ws.Name & "'!$B$5"    'Project #
                .Cells(x, "C").Formula = "='" & ws.Name & "'!$A$1"    'Project Name
                .Cells(x, "D").Formula = "='" & ws.Name & "'!$B$8"    'Project Engineer
                .Cells(x, "E").Formula = "='" & ws.Name & "'!$B$11"    'In-service Due
                .Cells(x, "F").Formula = "='" & ws.Name & "'!$E$6"    '30% Due
                .Cells(x, "G").Formula = "='" & ws.Name & "'!$F$13"    '30% Success
                .Cells(x, "H").Formula = "='" & ws.Name & "'!$E$7"    '60% due
                .Cells(x, "I").Formula = "='" & ws.Name & "'!$F$14"    '60% Success
                .Cells(x, "J").Formula = "='" & ws.Name & "'!$E$8"    '90% due
                .Cells(x, "K").Formula = "='" & ws.Name & "'!$F$15"    '90% Success
                .Cells(x, "L").Formula = "='" & ws.Name & "'!$E$5"    'Material Forecast due date
                .Cells(x, "M").Formula = "='" & ws.Name & "'!$F$11"    'Materials Forecast Success
                .Cells(x, "N").Formula = "='" & ws.Name & "'!$B$15"    'Non Stores Items
                .Cells(x, "O").Formula = "='" & ws.Name & "'!$B$16"    'Non Stores Items Ordered on time
                .Cells(x, "P").Formula = "='" & ws.Name & "'!$A$17"    'Non Stores Items Success
            End If
        Next

    End With

【问题讨论】:

    标签: vba excel hyperlink


    【解决方案1】:

    代替

    .Cells(x, "A").Formula = "=ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _'" & ws.Name & "'"
    

    使用

    .Hyperlinks.Add Anchor:=.Cells(x, "A"), _
                    Address:="", _
                    SubAddress:= "'" & ws.Name & "'!A1", _
                    TextToDisplay:= ws.Name
    

    我假设您的代码正在With ActiveSheet(或等效)块内执行。

    【讨论】:

    • 这太完美了!我一直在努力解决这个问题,非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-22
    • 2018-06-11
    • 1970-01-01
    • 1970-01-01
    • 2015-09-25
    • 2021-10-30
    相关资源
    最近更新 更多