I've written quite a few macros that aid in the analysis of my collected experimental data. I'm now creating a user form that will display buttons for each of the macros I've written. However, as the first action of every button I want to include a macro to facilitate loading the tab delimited data. I recorded a macro of me importing the data with the settings I want and have been trying to incorporate this with GetOpenFilename() however if the cancel button is chosen from the file chooser the program crashes. I've tried various methods but they all seem to generate an error. Any help would be greatly appreciated.
Sub OpenText()
Dim OpenFile As String
MsgBox "Please select a text file", vbOKOnly
OpenFile = Application.GetOpenFilename("Textfiles (*.txt),*.txt", , "Open a textfile...")
If OpenFile = False Then GoTo Cancel
Workbooks.OpenFilename (OpenFile), Origin _
:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote _
, ConsecutiveDelimiter:=True, Tab:=True, Semicolon:=False, Comma:=False _
, Space:=True, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), Array _
(3, 1), Array(4, 1), Array(5, 1), Array(6, 1)), TrailingMinusNumbers:=True
Cancel:
MsgBox "The Cancel button was selected."
End Sub
Bookmarks