canselmi
04-05-2011, 12:27 PM
I've used the "Macro Record" to help with the VBA, but I need more help.
What I'm trying to do is this:
1. UserForm command button that will only allow the selection of only one .csv file. But I need the user to be able to browse to the csv.
2. Import the contents into a new (or existing) hidden worksheet called "Import".
I've found quit a few threads that kind of address this, but not exactly.
This is what the record macro creates:
Sub ImportCSV()
'
' ImportCSV Macro
'
'
ActiveWorkbook.Worksheets.Add
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;R:\R\River Ranch Radiology\Sales\38347401016.csv", Destination:=Range( _
"$A$1"))
.Name = "38347401016"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Application.Goto Reference:="ImportCSV"
End Sub
What I'm trying to do is this:
1. UserForm command button that will only allow the selection of only one .csv file. But I need the user to be able to browse to the csv.
2. Import the contents into a new (or existing) hidden worksheet called "Import".
I've found quit a few threads that kind of address this, but not exactly.
This is what the record macro creates:
Sub ImportCSV()
'
' ImportCSV Macro
'
'
ActiveWorkbook.Worksheets.Add
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;R:\R\River Ranch Radiology\Sales\38347401016.csv", Destination:=Range( _
"$A$1"))
.Name = "38347401016"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Application.Goto Reference:="ImportCSV"
End Sub