Export Text with Cell name

blujason

New Member
Joined
Jul 20, 2022
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hello Mr. Excel,

I have looked through the forum and cannot seem to get the proper answer to work.

I am trying to export text from one cell and use another cell as the file name - and go to a specific folder

An Example of my sheet is:
ResponseIdWriting Prompt 1Writing Prompt 2
1​
Text data
2​
Text data
3​
Text data
4​
Text data
5​
Text data
6​
Text data
7​
Text data
8​
Text data
9​
Text data
10​
Text data

On the export, the txt file would be named from ResponseID, and the txt file will include Column B or C. If I were to export row 4 - the file would be named 4.txt and contain the text entered under writing prompt 1 for that cell.

Make sense?

Thank you for any guidance.

Jason
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hi Jason,
For testing, prepare a folder named "temp" under the C drive.

VBA Code:
Sub Sample()
    Const sPath As String = "c:\temp\"    'output folder for text files
    Dim i As Long, f As Integer

    For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row    'last data row
        f = FreeFile
        Open sPath & Cells(i, 1).Value & ".txt" For Output As #f
        Print #f, Cells(i, 2).Value & Cells(i, 3).Value
        Close #f
    Next
    MsgBox "done"
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,950
Messages
6,122,436
Members
449,083
Latest member
Ava19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top