Create Txt file from Excel

prakashgusain

New Member
Joined
Dec 8, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello,
I want to create text files using Excel VBA.
Save them with cell value in column A and text file to contain text in column B

Column A Column B
FileName1 Content 1
FileName2 Content 2
FileName3 Content 3
FileName4 Content 4
FileName4 Content 5

Save all these files to Folder in desktop. Number of files goes 100+
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hi

prakashgusain

Codes below create the files in same folder, from where you will run it...
VBA Code:
Sub prakashgusain()
  pth = ThisWorkbook.Path
  Set myObj = CreateObject("Scripting.FileSystemObject")
      With myObj
            For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row
            fl_name = pth & "\" & Cells(i, 1).Value & ".txt"
                Set fl = .CreateTextFile(fl_name, True, True)
                fl.WriteLine (Cells(i, 2).Value)
                fl.Close
            Next
            Set fl = Nothing
   End With
   Set myObj = Nothing
   MsgBox "task complete"
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,092
Messages
6,123,063
Members
449,090
Latest member
fragment

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