rhino4eva
Active Member
- Joined
- Apr 1, 2009
- Messages
- 262
- Office Version
- 2010
- Platform
- Windows
Code:
Sub import()
'Application.Wait (Now + #12:00:05 AM#)
Dim fName, DrivePath
'Uses open file dialog box
Sheets("Sheet1").Select
DrivePath = "T:"
With Application.FileDialog(msoFileDialogFilePicker)
.InitialFileName = DrivePath & "*TCTB*.*"
.AllowMultiSelect = False
.Show
If .SelectedItems.Count > 0 Then fName = .SelectedItems(1)
Sheets("Sheet1").Range("m1") = fName
On Error Resume Next
End With
MsgBox "You have selected " & fName & " to import"
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & fName, Destination:=Range("a7"))
.FieldNames = True
.RowNumbers = False
.Name = fName
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 10
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = True
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 4, 1, 1, 4, 9, 1, 1, 1, 1, 1, 9, 9, 9, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
end sub
It basically imports a text file into a new sheet . I designed it for one person to use but inevitably every wants a go. The only problem is that everyone text file is just that tiny bit different and I need to make the ".TextFileColumnDataTypes = Array" variable. I have got a frontend userform so I can control the variable but as part of the test I tried a hardwired version first ie
code:
ImpArray = "1, 1, 1, 4, 1, 1, 4, 9, 1, 1, 1, 1, 1, 9, 9, 9, 1, 1, 1, 1, 1, 1, 1, 1"
.TextFileColumnDataTypes = Array(ImpArray)
the results weren't as expected ... what am I doing wrong ????
Last edited by a moderator: