[英]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.