Code: Select all
Sub ImportBC450()
Dim Msg As String
Dim wb As Workbook
Dim ws As Worksheet
Dim varFile As Variant
Set wb = ThisWorkbook
Set ws = wb.ActiveSheet
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.DisplayAlerts = False
Msg = vbCrLf & "You are about to import a source data file."
Msg = Msg & vbCrLf & vbCrLf & "You will be faced with a 'file open' dialogue, where you will need to select a source BC450 to import."
Msg = Msg & vbCrLf & vbCrLf & "Are you sure that you want to continue?"
Msg = Msg & vbCrLf & vbCrLf
If MsgBox(Msg, vbQuestion + vbYesNo, "Source Data File") = vbNo Then
Exit Sub
Else
varFile = Application.GetOpenFilename("All files (*.*), *.*")
If VarType(varFile) = vbBoolean Then
'User canceled dialog
Beep
Exit Sub
End If
'Import selected file
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & varFile, Destination:=Range("A1"))
.Name = ""
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileFixedColumnWidths = Array(19, 14, 8, 22, 16, 45, 21, 16)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End If
End Sub
Also, if possible, I would like to specify a row to start the import from, eg: row 74333. Is this possible?
Thanks for any advice.