Code to delete text from a .txt file

cs1ctp

Board Regular
Joined
Oct 7, 2005
Messages
122
Hi,

Is there VB code to delete the contents of a text file. Basically I am deleting an item from a text file, but have found the best way to do this is to re-write the text file omitting the deleted item. At the moment I have the code that re-writes the text file, but it is adding to rather than replacing the text in the text file. A simple work around would be simply to delete the contents of the text file. Is there code for this??

Many thanks in advance for your help

Chris
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
try this
Code:
Sub test_code()
Dim ff As Integer
On Error Resume Next
yourfile = "C:\any.txt" ''''''''''''''''' change to suit
Kill yourfile
On Error GoTo 0
 ff = FreeFile
Open yourfile For Append As #ff
Close #ff
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,455
Messages
6,055,540
Members
444,794
Latest member
HSAL

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