Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 24th, 2004, 02:28 PM
Registered User
Join Date: Aug 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default import data from text file to excel(VBA)

hi !
how can i import data from text file to excel(VBA), as my data has commas ,qoutes delimiters .
thanks in advance.

Old August 26th, 2004, 06:45 AM
Authorized User
Join Date: Aug 2004
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts

Try renaming the file if necessary with .txt suffix and use Excel File/Open.
The problem might be the " text delimiter. Can remove this in a text editor with Edit/Replace " with nothing.

Regards BrianB
Most problems occur from starting at the wrong place.
Use a cup of coffee to make Windows run faster.
It is easy until you know how.
Old August 26th, 2004, 11:36 PM
Authorized User
Join Date: Feb 2004
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts

Here is an example.

Sub ImportData()

    'Filename = the full path to Your txt file eg."C:\MyDocuments\Mytxt.txt"
    Open Filename For Input As #1
    Do While (Not EOF(1))
        ' In this case the file is delimited by , and contains several lines
    ' Read the file one line at the time
    Input #1, Streng

    'Input streng into and array
    StrArray = Split(Streng, ",")
    Call WriteToExcel(StrArray)
    Close #1
End Sub

Sub WriteToExcel(StrArray)
     For J = LBound(StrArray) To UBound(StrArray)
     'Do what you want to do with the data
    Next J
End Sub

Hope this is what you are looking for.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Import from Excel sheet to a text file zone Excel VBA 1 July 26th, 2007 10:34 AM
How to import data from text file? starnet SQL Server 2000 1 September 18th, 2006 06:56 AM
Text file import to data grid missing some values [email protected] ASP.NET 1.0 and 1.1 Basics 2 April 14th, 2006 10:42 AM
VBA access List data to text file Data-Base Access VBA 6 September 15th, 2005 04:04 PM
Apply Custom template & import data from text file shampabera Excel VBA 2 August 8th, 2005 07:41 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.