Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Thread Tools Search this Thread
Old 21-03-2009
Join Date: Jan 2009
Posts: 91
Vba import text files

Hi friends,

I am facing an issue with VBA.I want to import some of text files in VBA. I have heard from my friends that it's possible but i don't know how to do it.

Can anyone help me out with this issue.

Intel Core 2 Duo 2.8 Ghz
915 MSI Motherboard with Intel chipset
1gb RAM

200gb HDD
Reply With Quote
Old 24-03-2009
Join Date: Dec 2008
Posts: 79
Re: Vba import text files

Try to use the following code.

Sub GetTextFile()
    Dim sFile As String
    Dim sInput As String
    Dim lFNum As Long
    Dim vaFields As Variant
    Dim i As Long
    Dim lRow As Long
    Dim vaStrip As Variant
    Const sDELIM = "^" 'Set the delimeter
    lFNum = FreeFile
    sFile = "C:CaratDelim.txt"
    vaStrip = Array(vbLf, vbTab) 'list the text to strip
    'Open the file
    Open sFile For Input As lFNum
    'Loop through the file until the end
    Do While Not EOF(lFNum)
        Line Input #lFNum, sInput 'input the current line
        'remove the unwanted text
        For i = LBound(vaStrip) To UBound(vaStrip)
            sInput = Replace(sInput, vaStrip(i), "")
        Next i
        'split the text based on the delimeter
        vaFields = Split(sInput, sDELIM)
        lRow = lRow + 1
        'Write to the worksheet
        For i = 0 To UBound(vaFields)
            Sheet1.Cells(lRow, i + 1).Value = vaFields(i)
        Next i
    Close lFNum
End Sub
Reply With Quote

  TechArena Community > Software > Software Development
Tags: , , ,

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads for: "Vba import text files"
Thread Thread Starter Forum Replies Last Post
Import a text file in JTextPane Ash maker Software Development 5 22-01-2010 11:17 AM
How to Import all text data in Excel spreadsheet racer Tips & Tweaks 1 06-01-2010 10:38 PM
import text file into ms access Clay Aiken Windows Software 2 23-06-2009 08:30 PM
How to import Text into Access through VBA appueye Software Development 2 17-04-2009 11:10 PM
What is the easiest way to convert unix/linux text files to DIS/Win text files? Antonio00 Windows XP Support 5 22-12-2007 07:52 AM

All times are GMT +5.5. The time now is 03:37 PM.