If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Deleting Content Of Flat *.txt File From Excel

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-02-04, 15:38
Alexxx12 Alexxx12 is offline
Registered User
 
Join Date: Sep 2002
Location: NJ
Posts: 139
Deleting Content Of Flat *.txt File From Excel

Hi,

Excel 2k
Win2k, Xp

I Have The Content Below In Rad.txt File I Want To Delete Without Deleting The File Rad.txt. How Can I Do It?

Nyc Med Doe |||||blue Call|12:30:32|12:31:38|00:01:04|john Doe
Medical Center |x|||||09:09:45|09:09:48|00:00:03|john Doe
Test To See One |||||blue Call|12:42:46|12:42:50|00:00:01|john Doe
Test To See One |x|||||12:42:46|12:43:19|00:00:05|john Doe
Personal Sevices |||||blue Call|12:44:58|12:46:00|00:01:01|john Doe

Thanks For Your Help.
Reply With Quote
  #2 (permalink)  
Old 12-03-04, 02:15
jparagg jparagg is offline
Registered User
 
Join Date: Oct 2003
Posts: 17
Hello,

It seems that you need a blank file named rad.txt.
(are you facing problem as you remove the contents of the file, the file is removed from the disk)

I am not sure I understood the requirement clearly, but here is what I suggest :

Sub CreateAfile()
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("c:\rad.txt", True)
a.Close
fs = Null
End Sub

This will overwrite the existing rad.txt creating a blank one.

HTH

jp
Reply With Quote
  #3 (permalink)  
Old 12-03-04, 08:14
Alexxx12 Alexxx12 is offline
Registered User
 
Join Date: Sep 2002
Location: NJ
Posts: 139
deleting the content of the flat file from excel

hi,

the problem is that the file name may vary:

"\\.....\" & range("C1").value & "Rat.txt"

What I need is a procedure that only deletes the content, not the file.

Thanks.
Reply With Quote
  #4 (permalink)  
Old 12-03-04, 08:47
DavidCoutts DavidCoutts is offline
Registered User
 
Join Date: Jan 2004
Location: Aberdeen, Scotland
Posts: 1,067
you can just do this if you want

Code:
Sub ClearFile()
    Dim mynum As Integer
    
    mynum = FreeFile
    Open "test.txt" For Output As #mynum
    Write #mynum,
    Close #mynum
End Sub
or else kill and recreate the file from a variable or a refrence to it's name

Dave
Reply With Quote
  #5 (permalink)  
Old 12-04-04, 12:34
savbill savbill is offline
Registered User
 
Join Date: Feb 2004
Posts: 533
Like David pointed out you can use the Open text function to read write to a text file. Also Ref the Get, Put methods of the Open Function. I don't think there's a way to delete one line directly. Either keep the lines in a spreadsheet then write the file based on the spread sheet or (more complex) read the file into an array, then write the file out from the array, skipping the line you want deleted.



/*
__________________
~

Bill
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On