We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now


Read comma delimited text flie into vba variables

Medium Priority
Last Modified: 2013-11-27
Using VBA 2000, I need to read a comma seperated text file "C:\Textfile.txt".
It will always have only 1 line.
It could have 2 to 6 values at anytime.
I've attached the code that I've been trying. It is reading the file and storing the line of csv's into sTemp, but I haven't got "Split" to work. Not sure if I just don't know how to use it or if I should try something else.
I need to store each value in a variable. How can I accomplish this?

Dim sLayout, sTemp As String
    Dim Value$
    Open "C:\add_slide.txt" For Input As #2
    Line Input #2, Value$
    sTemp = Value$
    sLayout = Split(sTemp, ",")

Open in new window

Watch Question

Top Expert 2016

Dim sLayout, sTemp As String
    Dim Value$, j as integer
    Open "C:\add_slide.txt" For Input As #2
    Line Input #2, Value$
    sTemp = Value$
    sLayout = Split(sTemp, ",")

    for j=0 to ubound(sLayout)

          debug.print slayout(j)
    next j

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Top Expert 2010
Hello coperations07,

Please explain what you mean by "I haven't got "Split" to work".  That code should have rendered sLayout
as a zero-based array with the values from that line of text.




Thanks guys!
Split was working. I just didn't know how to get the data from it.
I just added variables like this and it works perfectly.

            s1 = sLayout(0)
            s2 = sLayout(1)
            s3 = sLayout(2)
            s4 = sLayout(3)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.