Hello,
I'm trying to write an If ElseIf Else statement where my macro looks up the extension of a file name (located in Sheet2 H1) and searches through a folder based on what that value is. If that file does not exist, it crashes my macro and takes me into debug mode. I'd rather have it come up with an error message, with another opportunity to get the file name correct. Since I'm still learning VBA, I'm going to give this example in a format that is easier to understand:
If Filename ends in ".csv" Then
Open C:\csv\ & sheet2.range("H1")
ElseIf Worksheets("Sheet2").Range("H1") = ".xls" Then
Open C:\xls\ & sheet2.range("H1")
ElseIf Worksheets("Sheet2").Range("H1") = ".txt" Then
Open C:\txt\ & sheet2.range("H1")
Else Message "Cannot Find File"
End If
Thanks in advance.
Bookmarks