Dan DeHaven
New Member
- Joined
- Aug 26, 2009
- Messages
- 45
I'm trying to create a automated/dynamic Text Import procedure and having trouble filling the array properties (.TextFileColumnDataTypes, .TextFileFixedColumnWidths) with range variables. I've named the ranges as this would be the ideal way to call them from code.
Here is the code:
So it's with the .TextFileColumnDataTypes and .TextFileFixedColumnWidths that I'm getting the Run-Time error 5 "Invalid procedure call or arguement".
Thanks!
Here is the code:
Code:
Sub ImportText()
Dim WB As Workbook
Dim odWS As Worksheet
Dim fsuWS As Worksheet
Dim fd As FileDialog
Dim fcInt As Integer
Dim fcStr As String
Dim spAr() As Variant
Dim dtAr() As Variant
Set WB = ThisWorkbook
Set odWS = WB.Sheets.Add
odWS.Name = "OriginalData"
Set fsuWS = WB.Sheets("FieldSetUp")
spAr = fsuWS.Range("SpanSpaces").Value
dtAr = fsuWS.Range("ImpDataTypes").Value
Set fd = Application.FileDialog(msoFileDialogFilePicker)
fcInt = fd.Show
If fcInt <> -1 Then
MsgBox "You chose cancel, why?"
Else
fcStr = fd.SelectedItems(1) & "."
End If
With odWS.QueryTables.Add(Connection:= _
"TEXT;" & fcStr, Destination:=Range("$A$1"))
.Name = "OriginalData"
.FieldNames = False
.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 = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = dtAr 'This way doesn't work
.TextFileFixedColumnWidths = Array(spAr) 'Nor this way
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub
So it's with the .TextFileColumnDataTypes and .TextFileFixedColumnWidths that I'm getting the Run-Time error 5 "Invalid procedure call or arguement".
Thanks!