Excel Macro to Export Text *.txt file

maxman

New Member
Joined
Dec 1, 2010
Messages
21
I want to create a macro that outputs the value of 3 cells, in the same column, to a *.txt file. Not CSV, only text. Each row is to represent a line of text not to exceed 50 characters. The file name would be "etch_text.txt". 1, 2, or 3 lines of text will be entered in the spread sheet by an operator. If only 1 or 2 lines are input, the empty cells must not output any charaters or codes.

The application is a laser etching system that reads a *.txt file for what needs to be marked. An excel spreadsheet is used to determine the font size, what to mark, etc, and the file name of the laser system template is generated and compared to a list of files in a directory. Currently, the operator must switch to NotePAD and enter the 1, 2, or 3 lines of text to etch. The NotePAD file is saved as etch_text.txt. Then the operator returns to the EXCEL application. I would like to eliminate the need to go to NotePAD and do everything in EXCEL.

thanks in advance

Maxman
 
It is not clear from your message whose procedure you are using, but I am sure I speak for taurean as well when I say... you are quite welcome, glad we could be of help to you.
Now re-reading 4th[if we could say that :)] OP's requirement I am quite sure that it is your code than mine.
 
Upvote 0

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hi All,

I'm a bit unsure if this is the right place to post this, but I have a very similar problem, only a bit more complicated.

All my info is in one large Excel sheet, and needs to be split into multiple txt files, across several folders, according to a very specific rule.

Output text file and folder structure must follow the rule: C:\output\"Family"\"Child".txt

I've got ~260 "Families" (each is unique) and ~1690 "Children" (each is unique), spread throughout the sheet, according to specific intervals. Each "Child".txt needs to contain a specific configuration of text lines, but for simplicity, let's leave them blank for now. My main focus is simply to generate these text files according to the above paths. Folders need to be created automatically, if possible.

The excel sheet intervals are as follows:
"Families" occupy A3 to A261
"Children" occupy A265 to A1954 and each child has a horizontal connection to its family (B265 to B1954).

How could one go about generating the folders and text files automatically? Let's consider for now that each "Child".txt file contains only one line, such as "test".

Thanks in advance!
 
Upvote 0
Hi All,

I'm a bit unsure if this is the right place to post this, but I have a very similar problem, only a bit more complicated.

All my info is in one large Excel sheet, and needs to be split into multiple txt files, across several folders, according to a very specific rule.

Output text file and folder structure must follow the rule: C:\output\"Family"\"Child".txt

I've got ~260 "Families" (each is unique) and ~1690 "Children" (each is unique), spread throughout the sheet, according to specific intervals. Each "Child".txt needs to contain a specific configuration of text lines, but for simplicity, let's leave them blank for now. My main focus is simply to generate these text files according to the above paths. Folders need to be created automatically, if possible.

The excel sheet intervals are as follows:
"Families" occupy A3 to A261
"Children" occupy A265 to A1954 and each child has a horizontal connection to its family (B265 to B1954).

How could one go about generating the folders and text files automatically? Let's consider for now that each "Child".txt file contains only one line, such as "test".

Thanks in advance!


I'm not sure i understood what you want but this might help you out. What i did in my case was i created a commandbutton that would send the excel info to a txt file i created. The code bellow separates column 1 from 2 using ";". What you have to do is change the range and the print.



Private Sub CommandButton2_Click()
Dim iFile As Integer, j As Integer
iFile = FreeFile
Open "C:\output\"Family"\"Child".txt" For Output As #iFile
For j = 2 To Range("B" & Rows.Count).End(xlUp).Row
Print #iFile, Range("B" & j).Value & ";" & _
Range("C" & j).Value & ";" & Range("D" & j).Value & ";" & Range("E" & j).Value & "" & Range("F" & j).Value
Next j
Close #iFile
End Sub
 
Upvote 0

Forum statistics

Threads
1,217,133
Messages
6,134,835
Members
449,890
Latest member
xpat

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