How Do I read .csv file to excel showing first column as text not general?

Scott Stevenson
Scott Stevenson used Ask the Experts™
on
Hi Experts,

I am looking to read the file into Excel having the first column as Text attribute 01 and not the General attribute 1  .  I assume if need code, but I am not sure how to change to text.

Workbooks.OpenText ReportCSV$  is too late.

An thoughts would be great appreciated!


 
-9090909LB.CSV
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
so you code vba, and want to inmport a file.
you can do it in workbook open event to see the code that suite your need, start registering a macro and import data (menu data->from text ) choose a file you like then, when it asks you ow should be
the columns, choose text. you will end up with a code simialr to the followig

Note: customize the file name using openfiledialog (google to see how wto use  Api to do some tricks that will work on different versions of Excel)or even a simple inputbox, or else you could read it form a manually read configuration file... ;-)


Option Explicit

Private Sub Workbook_Open()
 With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;C:\temp\yourFile.txt", Destination:=Range("$A$1"))
        .Name = "yourFile"
        .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 = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = False
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = True
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(2, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
End Sub

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial