Saving cells to separate .txt files with different names

Carey22

New Member
Joined
Dec 19, 2016
Messages
10
Hello

I'm new to Macros and I've been trying without any success to create a 'save as' macro in Excel. I have two columns of data, column A contains the file name I would like to create and column B contains the actual file contents. I have over 1,000 cells I would like to create separate text files for and save all in one folder.

I would be so grateful if someone could assist?

Thank you
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Please test with small sample data.
Code:
Sub txt()
Dim LR As Long, i As Long
Dim ws1 As Worksheet, ws2 As Worksheet
Const path = "C:\Users\Carey22\" 'Change this line to your folder name.
Set ws1 = Sheets("sheet1")
Set ws2 = Sheets("sheet2")
With ws2
    LR = ws1.cells(Rows.Count, 1).End(xlUp).row
    For i = 2 To LR
        .Range("A1").Value = ws1.cells(i, 2).Value
        .copy
        Application.DisplayAlerts = False
        ActiveWorkbook.SaveAs Filename:=path & ws1.cells(i, 1).Value & ".txt", _
        FileFormat:=xlText, CreateBackup:=False
        ActiveWorkbook.Close
        Application.DisplayAlerts = True
    Next
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,700
Members
448,979
Latest member
DET4492

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