Save names in Column to text files in folder

Excelaron

Board Regular
Joined
Sep 16, 2011
Messages
211
Column A
1 Name1
2 Name2
3 Name3
4 Name4
.
.
.
100 Name100


There could be hundres of rows

C:\Files\Name1.txt, Name2.txt, Name3.txt, Name4.txt....Name100.txt

I would like to select the names in column A down to a varied number of rows and have some VBA code use those names to and list names as text files. ( I know the files will be empty. I will use the empty text files to do a save as in some old legacy system and I dont have to type in 100's file names)

Thanks for any help
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Here is an example that you can adapt:


Code:
Sub Macro1()
Dim N As Long, ary() As Variant
N = Cells(Rows.Count, "A").End(xlUp).Row
ary = Range("A1:A" & N)
For i = LBound(ary) To UBound(ary)
    flname = "C:\TestFolder\" & ary(i, 1) & ".txt"
    ActiveWorkbook.SaveAs Filename:=flname, _
        FileFormat:=xlText, CreateBackup:=False
Next i
End Sub
 
Upvote 0
Thanks, but I get an error (ActiveWorkbook.SaveAs Filename:=Flname)

I found some code that works

Sub WriteText()
Dim firstrow As Integer, rownum As Integer, colnum As Integer
Dim filename As String
Dim Filelocation As String
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
Filelocation = "C:\Files\"
With ws
rownum = 3
While .Cells(rownum, 1) <> ""
filename = .Cells(rownum, 1).Value
Open (Filelocation & filename & ".txt") For Output As #1

colnum = 2
While .Cells(rownum, colnum) <> 0
Print #1, ws.Cells(rownum, colnum) & " ";
colnum = colnum + 1
Wend
Close #1
rownum = rownum + 1
Wend

End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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