View Full Version : Create text files with file names from excel column
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?
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
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")
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
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.