Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2002
    Location
    NJ
    Posts
    139

    Unanswered: 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.

  2. #2
    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

  3. #3
    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.

  4. #4
    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

  5. #5
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •