Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    224
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Delete a file inan Excel MAcro (Excel 2000)

    Hi,

    Can I delete a file from within an Excel macro, this would be a .txt file, I need to check if it is present and the delete if it is there before creating a new one.

    Thanks

    Mike

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete a file inan Excel MAcro (Excel 2000)

    Check the KILL function:

    Dim sFilename as String
    sFilename="c:datatest.txt"
    if dir(sFilename)="" then
    Kill sFilename
    End If

    Note that KILL effectively deletes the file without use of the recycle bin.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  3. #3
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    224
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete a file inan Excel MAcro (Excel 2000)

    Thanks Jan, that worked fine.. Regards Mike

  4. #4
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete a file inan Excel MAcro (Excel 2000)

    Shouldn't that If be:

    <pre> If Dir(sFilename) <> "" Then
    </pre>


    Dir returns null if there is no matching file.
    Legare Coleman

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete a file inan Excel MAcro (Excel 2000)

    Oops, of course.

    Silly me.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

Posting Permissions

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