Results 1 to 3 of 3

Cancel button with GetOpenFilename()

Threaded View

  1. #1
    Registered User
    Join Date
    06-13-2011
    Location
    Boulder, Colorado
    MS-Off Ver
    Excel 2010
    Posts
    61

    Cancel button with GetOpenFilename()

    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
    Last edited by Impartial Derivative; 07-26-2011 at 11:37 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1