Can only update the last link in the list of links

7 views
Skip to first unread message

Michael Munch

unread,
Jun 4, 2018, 3:04:12 AM6/4/18
to excel vba
Hi

My code crawls all external links and changes them, but it's only the last one that changes. Why is only the last and not all of them changed?

Yours sincerely
Michael


Private Sub cmdExecute_Click()
   
   Dim wb As Workbook
   Dim ExternalLinks As Variant
   Dim i As Long

   Set wb = ActiveWorkbook

   ExternalLinks = wb.LinkSources(Type:=xlLinkTypeExcelLinks)
   
   Application.DisplayAlerts = False
   Application.AskToUpdateLinks = False
   If VariantContent(ExternalLinks) = True Then  'Is there links?
      For i = 1 To UBound(ExternalLinks)
         wb.ChangeLink Name:=ExternalLinks(i), _
                       NewName:=Replace(LCase(ExternalLinks(i)), LCase(Me.txtOLD.Value), Me.txtNEW.Value), _
                       Type:=xlLinkTypeExcelLinks
      Next
   End If
   Application.DisplayAlerts = True
   Application.AskToUpdateLinks = True

   Unload Me

End Sub
Reply all
Reply to author
Forward
0 new messages