+ Reply to Thread
Results 1 to 5 of 5

Change Excel 'overwrite file?' macro

  1. #1
    Registered User
    Join Date
    08-08-2006
    Posts
    25

    Change Excel 'overwrite file?' macro

    Hi there

    I am trying to change the standard macro that warns you if you are saving a new file as one that already exists ("A file named .... already exists in this location. Do you want to replace it?)

    Basically, I am trying to change what happens when 'No' or 'Cancel' is clicked (I need to run my own macro) Is this possible, or do I need to write another similar macro that has the same function but executes before excel's default one?

    Any help or links to related topics appreciated

    Thanks

    Alex

  2. #2
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Hi,

    You should remove XL warning

    Application.DisplayAlerts = False

    And code your own Exit scenario ...

    HTH
    Carim

  3. #3
    Forum Contributor
    Join Date
    12-04-2003
    Posts
    360
    On the workbook save event

    You could use a filesearch to check for the presence of a file called the same as the one you trying to save, if there's a match do a procedure the end, else save.

    This method might still need the displayevents and would therefore still overwrite the file if you select no.

  4. #4
    Registered User
    Join Date
    08-08-2006
    Posts
    25
    Thanks for the advice both of you.

    I thought I had it sussed, but I'm finding it difficult to write a code that checks if an exisiting file already has that name.

    How would I go about a message box (vbYesNo) warning that executes if the filename you are trying to save as already exists in any of THREE directories!? IS this even possible?

    (Otherwise, how would I simply check if the filename to be saved already exists in the CURRENT directory you are trying to save in?)

    MANY thanks

    Alex

  5. #5
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Alex

    Here is one way to check if a file exists.

    Repeat for each file and/or directory

    Sub FileCheck()
    If Dir("c:\Temp\Book2.xls") <> "" Then
    MsgBox "File Exists"
    End If
    End Sub

+ 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