I'm trying to loop through some sheets in a workbook to update hyperlink in column A but I keep encountering various issues I'm not able to understand.
Private Sub Workbook_Open()
Dim HL As Hyperlink
Dim lnk As String 'actual link
Dim ori As String 'old link
Dim nvr As String
Dim forn As String 'hyperlink name
Dim ws As Worksheet
nvr = ThisWorkbook.Path 'new path
ori = Sheets("check list e parametri").Range("a28").Value 'old path
For Each ws In ThisWorkbook.Worksheets
Select Case ws.Name
Case "Fatture consegnate 2019", "Progress", "check list e parametri", "Fatture consegnate backup" 'sheets to skip
Case Else
With ActiveWorksheet
.Range("a2:a200").Select
For Each HL In Selection.Hyperlinks
forn = HL.TextToDisplay
lnk = HL.Address 'complete link
lnk = Replace(lnk, ori, nvr) 'replace old path with new path
ActiveSheet.Hyperlinks.Add Anchor:=HL.Range, Address:=lnk, TextToDisplay:=forn 'new hyperlink with name
Next HL
End With
End Select
Next ws
Sheets("check list e parametri").Range("a28") = nvr 'new path saved for the future
End Sub
I'm pretty new to VBA so my knowledge is limited and my code is.. rude at least. I tried various looping alternatives, but the code continues to give me errors. I'm expecting the code to loop through all the non-excluded worksheets each time the workbook is open, identify the hyperlink in the selected range, replace the old path with the new and keep the same displayed name. (I'm using Excel 2013)