Hello,
I would like to create a code that allows you to select the directory, and import each csv file into a worksheet. I would like each csv file to be ten columns apart. I am not looking for someone to write the code for me because I want to learn and understand it. I have found some code that allows me to select the directory.
Dim intResult As Integer
Dim strPath As String
Dim i As Integer
Application.FileDialog(msoFileDialogFolderPicker).ButtonName _
= "Select Path"
intResult = Application.FileDialog(msoFileDialogFolderPicker).Show
If intResult <> 0 Then
Call MsgBox(Application.FileDialog(msoFileDialogFolderPicker _
).SelectedItems(1), vbInformation, "Selected Folder")
End If
If I want to set a string variable to the directory, how do I do that? I found this chunk of code online and I don't completely understand it. Also, I recorded a macro of one csv file I imported to see what code was used. I put an X in the directory name and a Y in the file name. Would I be able to put the string variable where I put X?
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;\\X.csv" _
, Destination:=Range("$A$10"))
.Name = "Y"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Also, how would I going to the next file in the folder?
Thanks, Natalie
Bookmarks