+ Reply to Thread
Results 1 to 3 of 3

Force overwrite when using SaveAs

Hybrid View

  1. #1
    Registered User
    Join Date
    04-13-2007
    Posts
    1

    Force overwrite when using SaveAs

    I have looked through the forum for an answer to this but I could not find one. Is there a way to use SaveAs without having to select Yes to overwrite files that already exist?

    Revise: I figured a way around the problem by detecting and deleting a file by the name of the file you are trying to save.

    Code:

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
        'Creates a file system object with which to manipulate files
        Set fs = CreateObject("Scripting.FileSystemObject")
        'The file name you want to save as
        FName = "file name"
        'Detects if the file already exists and if so deletes it
        If fs.FileExists(FName) Then fs.DeleteFile (FName)
        ThisWorkbook.SaveAs Filename:=FName
    End Sub
    Last edited by shawnpgorman; 04-13-2007 at 10:23 PM. Reason: Figured it out for myself.

  2. #2
    Forum Contributor
    Join Date
    12-12-2005
    Posts
    667
    That's the difference between Save and Save as.
    Use: ActiveWorkbook.Save
    Best regards,

    Ray

  3. #3
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    before the save command use

    application.displayalerts = false
    after the save command use
    application.displayalerts = true
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1