Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
CPearsons import text code
Using the code below works well except that it drops the lead zeros
for a couple of the columns. Is their a way to retrieve exactly whats in the text file. Thanks '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''' ' ImportTextFile ' This imports a text file into Excel. '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''' Public Sub ImportTextFile(FName As String, Sep As String) Dim RowNdx As Long Dim ColNdx As Integer Dim TempVal As Variant Dim WholeLine As String Dim Pos As Integer Dim NextPos As Integer Dim SaveColNdx As Integer Application.ScreenUpdating = False 'On Error GoTo EndMacro: SaveColNdx = ActiveCell.Column RowNdx = ActiveCell.row Open FName For Input Access Read As #1 While Not EOF(1) Line Input #1, WholeLine If Right(WholeLine, 1) < Sep Then WholeLine = WholeLine & Sep End If ColNdx = SaveColNdx Pos = 1 NextPos = InStr(Pos, WholeLine, Sep) While NextPos = 1 TempVal = Mid(WholeLine, Pos, NextPos - Pos) Cells(RowNdx, ColNdx).Value = TempVal Pos = NextPos + 1 ColNdx = ColNdx + 1 NextPos = InStr(Pos, WholeLine, Sep) Wend RowNdx = RowNdx + 1 Wend EndMacro: On Error GoTo 0 Application.ScreenUpdating = True Close #1 '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''' ' END ImportTextFile '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''' End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How to Start Excel in Text Import Wizard for data import | Setting up and Configuration of Excel | |||
VBA code to import stacked text files | Excel Programming | |||
How to Use Chip Pearson's Text Import Code | Excel Programming | |||
Import HTML code from a text file. | Excel Programming | |||
Use VBA code to open a text file with the import wizard | Excel Programming |