mercredi 26 octobre 2016

VBA IF statement does not work

I have the below code in Excel VBA where it should "open and read" a file if hyperlinked file exists. But somehow it opens the file even when the hyperlinked file does not exists and then Excel stops responding. I think there something wrong with the "If" statement. Any help would be great! Thank you!

Sub test()

         For k = 11 To 50
        On Error Resume Next
        If Len(Dir(Cells(k, 33).Hyperlinks(1).Address)) > 0 Then

            myFile = Cells(k, 32).Hyperlinks(1).Address

            Open myFile For Input As #1

            Do Until EOF(1)
                Line Input #1, textline
                text = text & textline
            Loop

            Close #1
        End If    
    Next k
End Sub

Aucun commentaire:

Enregistrer un commentaire