Results 1 to 2 of 2

Any method to write the Text file into the Excel sheet in VBA

This is a discussion on Any method to write the Text file into the Excel sheet in VBA within the Excel Questions forums, part of the Question Forums category; Any easiest method to write the text file into the Excel sheet....

  1. #1
    Board Regular
    Join Date
    Nov 2008
    Posts
    51

    Default Any method to write the Text file into the Excel sheet in VBA

    Any easiest method to write the text file into the Excel sheet.

  2. #2

    Join Date
    Feb 2003
    Location
    Gurgaon/Thrissur
    Posts
    2,615

    Default Re: Any method to write the Text file into the Excel sheet in VBA

    Hi Divya,

    Try something like..

    Code:
    Sub kTest()
    Dim txt As String, FileFolder   As String, fs As Object
    Dim w(), i  As Long, c  As Long, n  As Long, x, FileName As String
    FileFolder = "C:\Test\" 'change to suit
    FileName = "Test.txt" 'change to suit
    Set fs = CreateObject("Scripting.FileSystemObject")
    txt = fs.opentextfile(FileFolder & FileName).readall
    x = Split(txt, vbCrLf)
    ReDim w(1 To UBound(x) + 1, 1 To UBound(Split(x(0), vbTab)) + 1)
    For i = 0 To UBound(x)
        n = n + 1
        For c = 0 To UBound(Split(x(i), vbTab))
            w(n, c + 1) = Split(x(i), vbTab)(c)
        Next
    Next
    With Range("a1")
        .Resize(n, UBound(w, 2)).Value = w
    End With
    End Sub

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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


DMCA.com