簡體   English   中英

使用 excel 宏更新超鏈接

[英]Update hyperlinks with an excel Macro

在此處輸入圖像描述我正在嘗試為 Excel 工作表上的所有嵌入式超鏈接添加擴展名。 我一次做一個單元格記錄了一個宏,但效率不高。 有人可以幫我簡化宏,以便它知道查看所有超鏈接、打開並在現有超鏈接的末尾插入附加信息。

Sub Macro5()
'
' Macro5 Macro
' test
'
' Keyboard Shortcut: Ctrl+Shift+H
'
    Range("H1").Select
    ActiveCell.FormulaR1C1 = "?u=76208058&auth=true"
    Range("C2").Select
    Selection.Hyperlinks(1).Address = _
        "https://www.linkedin.com/learning/teaching-techniques-classroom-management?u=76208058&auth=true"
    Range("C3").Select
    Selection.Hyperlinks(1).Address = _
        "https://www.linkedin.com/learning/learning-how-to-increase-learner-engagement?u=76208058&auth=true"
    Range("C4").Select
    Selection.Hyperlinks(1).Address = _
        "https://www.linkedin.com/learning/teaching-with-technology?u=76208058&auth=true"
End Sub

將字符串添加到超鏈接

  • 第一個代碼更改指定工作表中所有單元格的超鏈接地址,而第二個代碼僅更改工作表指定列中的超鏈接地址。
  • 適當調整常量部分中的值。
  • If語句檢查當前超鏈接是否已被修改。

編碼

Option Explicit

' For the whole sheet:
Sub addTailSheet()

' Keyboard Shortcut: Ctrl+Shift+H

    Const SheetName As String = "Sheet1"
    Const TailCell As String = "H1"

    Dim ws As Worksheet
    Dim hyp As Hyperlink
    Dim Tail As String

    Set ws = ThisWorkbook.Worksheets(SheetName)

    With ws
        Tail = .Range(TailCell).Value
        For Each hyp In .Hyperlinks
            If Right(hyp.Address, Len(Tail)) <> Tail Then
                hyp.Address = hyp.Address & Tail
            End If
        Next
    End With

    MsgBox "Hyperlinks modified."

End Sub

' For a column:
Sub addTailColumn()

' Keyboard Shortcut: Ctrl+Shift+H

    Const SheetName As String = "Sheet1"
    Const TailCell As String = "H1"
    Const TailColumn As Variant = "C"  ' e.g. "C" or 3

    Dim ws As Worksheet
    Dim hyp As Hyperlink
    Dim Tail As String

    Set ws = ThisWorkbook.Worksheets(SheetName)

    With ws.Columns(TailColumn)
        Tail = .Parent.Range(TailCell).Value
        For Each hyp In .Hyperlinks
            If Right(hyp.Address, Len(Tail)) <> Tail Then
                hyp.Address = hyp.Address & Tail
            End If
        Next
    End With

    MsgBox "Hyperlinks modified."

End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM