Create text Files from every row in an Excel spreadsheet

后端 未结 4 1855
死守一世寂寞
死守一世寂寞 2020-12-01 20:29

I need help creating separate text files from each row in an excel spread sheet called \"worksheet\". I want the text files to be named with content of Column A, with colum

4条回答
  •  误落风尘
    2020-12-01 20:41

    I used the simple code below for saving my excel rows as a text file or many other format for quite a long time now and it has always worked for me.

    Sub savemyrowsastext()
    Dim x

    For Each cell In Sheet1.Range("A1:A" & Sheet1.UsedRange.Rows.Count)
    ' you can change the sheet1 to your own choice
    saveText = cell.Text
    Open "C:\wamp\www\GeoPC_NG\sogistate\igala_land\" & saveText & ".php" For Output As #1
    Print #1, cell.Offset(0, 1).Text
    Close #1
    For x = 1 To 3 ' Loop 3 times.
    Beep ' Sound a tone.
    Next x
    Next cell
    End Sub

    Note:

    1. Column A1 = file title
    2. column B1 = file content
    3. Until the last row containing text (ie empty rows)

    in reverse order, if you want to make it like this;

    1. Column A1 = file title
    2. column A2 = file content
    3. Until the last row containing text (ie empty rows), just change Print #1, cell.Offset(0, 1).Text to Print #1, cell.Offset(1, 0).Text

    My folder location = C:\wamp\www\GeoPC_NG\kogistate\igala_land\
    My file extension = .php, you can change the extension to your own choice (.txt, .htm & .csv etc) I included bip sound at the end of each saving to know if my work is going on
    Dim x
    For x = 1 To 3 ' Loop 3 times.
    Beep ' Sound a tone.

提交回复
热议问题