Export, Name, Save as Text File

golfnut324

Board Regular
Joined
Jul 12, 2006
Messages
93
Could someone tell me the best way to tackle this issue? I have a three column table (A, B & C) that looks like this:
Book1.xls
ABCD
1ITEMTEXTFILEEXT
2AAC42011VERYLONGTEXTHERE.txt
3AVV55432VERYLONGTEXTHERE.txt
4XXR66575VERYLONGTEXTHERE.txt
5>1100rows
Sheet1







Table has about 1100 rows with item number, long text and .txt as above. I would like to export each text field to a Notepad (or other text) file and save the file as ""A".txt".

Is this best handled via VBA from Excel or from Word or...? Being that I barely know how to spell V B A, is this high level and should I look for professional help?

Thanks for any help and/or advice on this question.

Craig
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Hi Golfnut324,

Can I check I unserstand correctly? For each row you want a seperate text file, named after the item number and the text being the text from column b adjacent (so this will create c. 1100 files...)

If so, try the following:

Code:
Sub Export_To_TextFile()
Range("a2").Select
Do While Not ActiveCell = ""
    Set fso = CreateObject("Scripting.Filesystemobject")
    Set ts = fso.CreateTextFile(ActiveCell.Value & ".txt", True)
 
    ts.Write ActiveCell.Offset(, 1).Text
 
    Set fso = Nothing
    Set ts = Nothing
 
    ActiveCell.Offset(1).Select
Loop
End Sub

I've tested this and it appears to work fine - It will save the files to your default (normally My Documents) - so you need to be sure that there aren't currently text files with conflicting file names that you need to keep because this file will write over them...

Let me know if there's anything else you need (are you ok with inserting modules etc to input the code?).

Hope that helps.


Arthur =D
 
Upvote 0
Thank you so much for the help. I will try it right now and post back. I can enter code into module, sometimes I get confused on how to call the code but I will try.

Thanks again!
 
Upvote 0
Hi Golfnut324,

Can I check I unserstand correctly? For each row you want a seperate text file, named after the item number and the text being the text from column b adjacent (so this will create c. 1100 files...)

If so, try the following:

Code:
Sub Export_To_TextFile()
Range("a2").Select
Do While Not ActiveCell = ""
    Set fso = CreateObject("Scripting.Filesystemobject")
    Set ts = fso.CreateTextFile(ActiveCell.Value & ".txt", True)
 
    ts.Write ActiveCell.Offset(, 1).Text
 
    Set fso = Nothing
    Set ts = Nothing
 
    ActiveCell.Offset(1).Select
Loop
End Sub

I've tested this and it appears to work fine - It will save the files to your default (normally My Documents) - so you need to be sure that there aren't currently text files with conflicting file names that you need to keep because this file will write over them...

Let me know if there's anything else you need (are you ok with inserting modules etc to input the code?).

Hope that helps.


Arthur =D


ABSOLUTELY OUTSTANDING!! Thank you, Thank you and Thank you!

Craig
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,047
Members
449,064
Latest member
scottdog129

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