I have a Macro (below) that opens the dialog box to choose a file and opens it into the 'Invest' sheet, then runs a macro to breakdown the Invest file to selected data
However, If somebody press's cancel or closes the dialog box the macro to breakdown the Invest sheet still runs.
Can somebody help me stop this bug, So if no file is selected the breakdown macro won't run?
Sub Import()
' Imports file '
Application.ScreenUpdating = False
Dim WS As Worksheet, strFile As String
Set WS = ActiveWorkbook.Sheets("Invest")
strFile = Application.GetOpenFilename("Text Files (*.csv),*.csv", , "Please selec text file...")
With WS.QueryTables.Add(Connection:="TEXT;" & strFile, _
Destination:=WS.Range("A1"))
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
' Imports file '
'''''''
'RUN MACRO CODE HERE
'''''''
End Sub