• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Check if external link exists before updating

dparteka

Member
I have a main-workbook that has hundreds of links to sub-workbooks. The sub-workbooks get created daily so their quantity is always growing day by day. The main-workbook already has all the links to the existing sub-workbooks in it and also the ones that have yet to be created.

I'm using the code shown below in a commandbutton to perform the link updates as needed. That code is for the first two links, all the others are the same except 18-xxx changes.

This works fine except when it gets to the first link that does not exist, when that happens it wants to be directed to the location of the link which does not exist.

The question: Is there code that can skip over the ones that do not have a link or code that checks if there is a link and if not then moves on. I've tried On Error Resume Next but this doesn't work, probably because it's not really an error.

Thank you for looking, your help will be genuinely appreciated.

Code:
  ActiveWorkbook.UpdateLink Name:= _
  "H:\Public\Quality Assurance\Issue Resolution Reports\2018\Records\18-001.xlsm" _
  , Type:=xlExcelLinks

  ActiveWorkbook.UpdateLink Name:= _
  "H:\Public\Quality Assurance\Issue Resolution Reports\2018\Records\18-002.xlsm" _
  , Type:=xlExcelLinks
 
Maybe?
Code:
 Sub checkdir()
    Dim FilePath As String
    FilePath = "H:\Public\Quality Assurance\Issue Resolution Reports\2018\Records\18-*.xlsm"
    If Dir(FilePath) <> "" Then
        'your code
    Else
        MsgBox "File doesn't exist."
    End If
End Sub
or
Code:
 Sub doesWBexist()
    With Application.FileSearch
        .LookIn = "H:\Public\Quality Assurance\Issue Resolution Reports\2018\Records"
        .Filename = "18-*.xlsm"
            If .Execute > 0 Then
                'your code
            Else
                MsgBox "File doesn't exist."
            End If
    End With
End Sub
 
UPDATE... it looked as if this was working, it runs through the code without errors but it's not updating the links. Can anyone see what I'm missing here, I sure can't.
Code:
Private Sub CommandButton9_Click()
'Update Petition Links
    With ApplicationFileSearch
        LookIn = "H:\Public\Quality Assurance\Issue Resolution Reports\2018\Records"
        Filename = "18-*.xlsm"
            If Execute > 0 Then
    ActiveWorkbook.UpdateLink Name:= _
        "H:\Public\Quality Assurance\Issue Resolution Reports\2018\Records\18-001.xlsm" _
        , Type:=xlExcelLinks
    ActiveWorkbook.UpdateLink Name:= _
        "H:\Public\Quality Assurance\Issue Resolution Reports\2018\Records\18-002.xlsm" _
        , Type:=xlExcelLinks
                   Else
                Exit Sub
            End If
    End With
End Sub
 
Back
Top