Please help....
I'm trying to get my IF statement to 'Exit' at this line if there is nothing in the variable strFile.
This is the line of code -
If strFile <> "" Then
End If
But the program just ignores it and carries on through. What am I doing wrong?
Sub Check()
Dim ws As Worksheet, strFile As String
If Not WksExists("temp") Then
ActiveWorkbook.Worksheets.Add After:=Worksheets(Worksheets.Count)
ActiveSheet.Name = "temp"
Set ws = ActiveWorkbook.Sheets("temp")
strFile = Application.GetOpenFilename("Text Files (*.csv),*.csv")
If strFile <> "" Then
End If
With ws.QueryTables.Add(Connection:="TEXT;" & strFile, Destination:=ws.Range("A1"))
.TextFileParseType = xlDelimited
.TextFileCommaDelimiter = True
.Refresh
End With
Else
MsgBox "Worksheet temp already exists. Change this name to the Year and Teaching Group of your class. Then try again."
End If
End Sub
Function WksExists(wksName As Variant) As Boolean
On Error Resume Next
WksExists = CBool(Len(Worksheets(wksName).Name) > 0)
End Function
Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
Bookmarks