Results 1 to 2 of 2

Thread: replace existing file

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    118
    I want to overwrite a file if it already exists, with an
    "example.txt already exists, overwrite existing file?" MsgBox prompt first. When I save an existing file now, it just names it "example2.txt". How do I do this?

  2. #2
    Lively Member
    Join Date
    Apr 2000
    Location
    Rafaela (Argentine)
    Posts
    107
    Try the following code (you have to add Microsoft Scripting Runtime (SCRRUN.DLL) in Project|References).

    Dim fs As FileSystemObject
    Set fs = CreateObject("Scripting.FileSystemObject")
    If fs.FileExists("c:\example1.txt") Then
    If MsgBox("example.txt already exists, overwrite existing file?", vbYesNo) = vbYes Then
    fs.DeleteFile "c:\example1.txt"
    ' Save the file using example1.txt
    Else
    ' Ask for another name?
    End If
    Else
    ' Save the file using example1.txt
    End If

    Complete the code acording to your needs.

Posting Permissions

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



Click Here to Expand Forum to Full Width