Help write to a text file, a bit confused.

mrmagoo_83

Board Regular
Joined
Mar 7, 2005
Messages
82
I need some help. I have tried to do this on my own using other examples, but I am a bit lost.

I have a sheet in my excel file, a lot of data in column 1. I am wanting to open a text file and write all that data to that text file.

Each line in the column is like "The letter is", the macro adds a charater, so the column then looks like "The letter is A", then B, then C, etc...

I want to write the entire column to a text file such as A.txt (when everything is A) and B.txt when everything is (B).

I have the macro to run through and edit each line and all that; however, I cannot get this thing to open a file for nothing.

I tried the following, where the Filename was a variable that ends up looking like "C:\A.txt"; but i get an error 438 on the line that attempts to open the text file. Line is also a string Variable that has already been set to a value.

Code:
Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFile(Filename)
    Set ts = f.OpenAsTextFile(ForAppending, TristateTrue)
    ts.Write Line
    ts.Close

Can anyone help?
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,215,049
Messages
6,122,864
Members
449,097
Latest member
dbomb1414

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