Results 1 to 2 of 2

macro to convert a txt file to excel file

Threaded View

vipin_pootheri macro to convert a txt file... 01-29-2013, 06:05 AM
patel45 Re: macro to convert a txt... 01-29-2013, 08:11 AM
  1. #1
    Registered User
    Join Date
    01-29-2013
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    2

    macro to convert a txt file to excel file

    Hi,

    I have written a macro for converting a txt file to excel file by giving file name and position as input from user
    the position is givenn as (1:5 6:7 etc..which means from 1 st position to 5 letters goes to 1 st colm of excel and from 6 th posn to 7 letters to 2 nd cell and so on)

    Dim text
    Dim fn
    Dim delim

    Public Sub CommandButton1_Click()
    fn = Application.GetOpenFilename
    If fn = False Then
    MsgBox "Nothing Chosen"
    Exit Sub
    End If
    End Sub
    Public Sub TextBox2_Change()
    text = UserForm1.TextBox2.text

    End Sub
    Private Sub CommandButton2_Click()
    Dim stext As Variant
    Dim arrays As Variant
    Dim fso As New FileSystemObject
    Dim txtStream
    Set txtStream = fso.OpenTextFile(fn)
    line = txtStream.ReadLine
    Dim row1, i As Integer
    Dim l, m As Integer
    Dim n As String
    Dim texts(2) As Integer


    row1 = 1
    i = 1
    Do While Not txtStream.AtEndOfStream

    arrays = split(text, " ")


    For k = LBound(arrays) To UBound(arrays)

    stext = split(arrays(k), ":")
    For i = 0 To 1
    texts(i) = CInt(stext(i))
    Next

    l = texts(0)
    m = texts(1)

    Cells(row1, i).Value = Mid(line, l, m)
    i = i + 1
    Next

    row1 = row1 + 1
    Loop
    txtStream.Close
    End Sub



    ---------------------------------------

    but is giving errors in the "texts(i) = CInt(stext(i)" line as subscript out of range

    pls help me on this
    Last edited by vipin_pootheri; 01-29-2013 at 06:30 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1