Check if a file can be opened or not and delete if not

Status
Not open for further replies.

Joe9238

Board Regular
Joined
Jul 14, 2017
Messages
67
Hi, does anyone have a code that can go through a list of hyperlinks and check if they can be opened or not? Some may be corrupt which is the reason they cannot be opened. This is what I have so far but the error command doesn't seem to work. The aim is to delete the hyperlinks that cannot be opened.
Code:
Sub testlinks()

On Error GoTo deleteit
   Dim wbTarget As Workbook
    Dim ary(3) As Variant
    Dim lRow As Long
    Dim CodeNames As Variant, i As Long


CodeNames = Range("Z2:Z" & Cells(Rows.Count, "Z").End(xlUp).Row)
For i = 1 To UBound(CodeNames, 1)
    If InStr(1, CodeNames(i, 1), ".xls") > 0 Then
Set wbTarget = Workbooks.Open(CodeNames(i, 1))
wbTarget.Close SaveChanges:=False
GoTo endit
End If
deleteit:
            CodeName = ""
endit:
Next i
Set wbTarget = Nothing
End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Duplicate https://www.mrexcel.com/forum/excel-questions/1056574-skip-corrupt-files-list.html#post5073464

Please do not post the same question multiple times. All clarifications, follow-ups, and bumps should be posted back to the original thread.
Per forum rules, posts of a duplicate nature will be locked or deleted (rule 12 here: Forum Rules).

If you do not receive a response, you can "bump" it by replying to it again, though we advise you to wait 24 hours before doing and not to bump a thread more than once a day.

 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,223,911
Messages
6,175,329
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top