+ Reply to Thread
Results 1 to 2 of 2

Compile Error - Importing multiple CSV files via GetOpenFilename

  1. #1
    Registered User
    Join Date
    03-02-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003
    Posts
    17

    Exclamation Compile Error - Importing multiple CSV files via GetOpenFilename

    When I click a button in a userform i want it to import the following CSV files which will always have the same column format (the with part was recorded and then modified to operate on the files selected)

    Please help thank you it doesn't get far

    Private Sub CommandButton1_Click()
    Dim X As Variant

    'Opens the dialog
    X = Application.GetOpenFilename("CSV Files (*.csv),*.csv,Text Files (*.txt),*.txt", 4, "Select Files", , True)



    'Loops through every file that is selected and opens each one
    For Y = 1 To UBound(X)

    With ActiveSheet.QueryTables.Add(Connection:= _
    "X(Y)", Destination _
    :=Range("1,(Y+(Y-1))"))
    .Name = "X(Y)"
    .FieldNames = True
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .TextFilePromptOnRefresh = False
    .TextFilePlatform = xlMacintosh
    .TextFileStartRow = 2
    .TextFileParseType = xlDelimited
    .TextFileTextQualifier = xlTextQualifierDoubleQuote
    .TextFileConsecutiveDelimiter = True
    .TextFileTabDelimiter = True
    .TextFileSemicolonDelimiter = False
    .TextFileCommaDelimiter = True
    .TextFileSpaceDelimiter = True
    .TextFileOtherDelimiter = """"
    .TextFileColumnDataTypes = Array(9, 5, 9, 1, 9, 9)
    .Refresh BackgroundQuery:=False
    .UseListObject = False
    End With

    Next Y

    End Sub

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Compile Error - Importing multiple CSV files via GetOpenFilename

    Please Login or Register  to view this content.
    If solved remember to mark Thread as solved

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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