Importing data from a text file into excel via VBA code

M0E-lnx

Registered User.
Local time
Today, 14:20
Joined
Sep 3, 2008
Messages
62
Hi, I need help figuring out how to do this

I have a template that I use a lot. From this template, I save the filled out .xls into a separate folder to keep for our records....

What I want is a way to do away with typing the same information over and over... so I have like 50 shipping addresses to ship to... so I'm thinking.. I can save the shipping address in a text file (one text file for each location). Then I can read this file every time I have to ship to this one location

How would I read this text file and put it's information in excel?
 
The obvious option is File System Object


Code:
Sub Read_text_File()

    Dim oFSO As New FileSystemObject
    Dim oFS

    Set oFS = oFSO.OpenTextFile("c:\textfile.TXT")

    Do Until oFS.AtEndOfStream
        activecell.value = oFS.ReadLine
        activecell.offset(1,0).select
    Loop

End Sub

This will read line-by line.

All you need to add the Microsoft Scripting Runtime in the reference.

Happy reading files:)
 

Users who are viewing this thread

Back
Top Bottom