+ Reply to Thread
Results 1 to 3 of 3

VBA to open .CSV file and format Columns A and C as text

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,176

    VBA to open .CSV file and format Columns A and C as text

    I have the code to open a .CSV file but when the file opens, it is converting some of the data, not all, to a date. As example, one of the cell values in column A is '5MAR'. When the file is opened, it is being converted to 03/05/2012. I need to leave this cell as '5MAR'. In other words I need to keep both columns in a text format. I did try to convert the columns to text after the file was open but it only proceeded to convert those cells to number. Any assistance appreciated. Thanks
        Prompt = "Select the data file to process."
        Path = Application.GetOpenFilename("Text Files (*.csv*), *.csv", , Prompt)
        
        Set wkbData = Workbooks.Open(Filename:=Path, ReadOnly:=True)

  2. #2
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,176

    Re: VBA to open .CSV file and format Columns A and C as text

    I tried to add the FieldInfo information but getting a 'Compile error' which indicates the 'Named argument not found' (FieldInfo)

        Prompt = "Select the data file to process."
        Path = Application.GetOpenFilename("Text Files (*.csv*), *.csv", , Prompt)
        
        Set wkbData = Workbooks.Open(Filename:=Path, FieldInfo:=Array(Array(1, 2), _
            Array(2, 1), Array(3, 2), Array(4, 1), Array(5, 1), Array(6, 1), _
            Array(7, 1), Array(8, 1), Array(9, 1), Array(10, 1)), ReadOnly:=True)

  3. #3
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,176

    Re: VBA to open .CSV file and format Columns A and C as text

    Bump no response

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1