PDA

View Full Version : Create text files with file names from excel column



Adwi
11-06-2018, 12:13 AM
Hi guys I would appreciate help with VBA code to create many text files named out of cells in a column within an excel sheet. Any ideas?

YasserKhalil
11-06-2018, 02:08 AM
Hello
Can you give more details please?

Adwi
11-06-2018, 06:08 AM
Hello
Can you give more details please?
Hi, so I have a list of file names in an excel spreadsheet and I want help to find code that will create blank text files that are named after the spreadsheet. Like one file per cell containing a file name.

YasserKhalil
11-06-2018, 10:25 AM
Try this code


Sub Test()
Dim fso As Object, txtFil As Object, c As Range


Set fso = CreateObject("Scripting.FileSystemObject")

For Each c In Range("A1:A3")
Set txtFil = fso.CreateTextFile(ThisWorkbook.Path & "\" & c.Value & ".txt", True)
txtFil.Close
Next c
End Sub

Adwi
11-06-2018, 07:52 PM
Try this code


Sub Test()
Dim fso As Object, txtFil As Object, c As Range


Set fso = CreateObject("Scripting.FileSystemObject")

For Each c In Range("A1:A3")
Set txtFil = fso.CreateTextFile(ThisWorkbook.Path & "\" & c.Value & ".txt", True)
txtFil.Close
Next c
End Sub


Hi, where will the new text file be created and saved?

YasserKhalil
11-06-2018, 08:09 PM
The new created text files will be in the same path of your workbook (ThisWorkbook.Path) >> you can change to your folder like that ("C:\MyFolder")

Adwi
11-06-2018, 11:55 PM
The new created text files will be in the same path of your workbook (ThisWorkbook.Path) >> you can change to your folder like that ("C:\MyFolder")

You're a legend. The code was perfect and I learned.

YasserKhalil
11-07-2018, 09:43 AM
You're welcome. Glad I can offer some help