Results 1 to 3 of 3

Save over file with new name but delete the old one

Threaded View

  1. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,929

    Re: Save over file with new name but delete the old one

    This code is more complex than necessary to do what you describe. It isn't necessary to change all those Application attributes to be able to save a file; the action won't trigger alerts, screen updating, calculation, or events. Also I don't see why you show the user a dialog box to save the file when you already know what name you want to use. That will allow the user to save it with any name, in any folder. If that's what you intend to do, you can use your original line of code for that.

    I would suggest the following, which I have tested:

    Private Sub CommandButton4_Click()
    
       Dim OriginalFileName As String
       Dim NewFileName As String
       
       NewFileName = ThisWorkbook.Path & "\" & Sheet8.Range("p46").Value
       OriginalFileName = ThisWorkbook.Path & "\" & ThisWorkbook.Name
       
       SaveAs NewFileName
       ' Application.Dialogs(xlDialogSaveAs).Show NewFileName & ".xlsm" ' or use this if you prefer
       Kill OriginalFileName
        
    End Sub
    I just gave this a second thought--do you have a BeforeSave or AfterSave event handler? In that case you may want to turn off events, but it all depends on what the handler does and whether you want to disable it for this particular save.
    Last edited by 6StringJazzer; 02-03-2015 at 01:26 PM. Reason: Added blue text
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Use Dir in If statement to delete old file, save new file
    By qwerty7 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-27-2015, 12:07 PM
  2. [SOLVED] Need help to save file to new folder and delete old file using same file name
    By tuongtu3 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-14-2012, 11:16 PM
  3. Perform a delete on file save
    By KevinThomas in forum Excel General
    Replies: 7
    Last Post: 03-01-2010, 10:50 AM
  4. VBA to save CSV file as XLS, delete CSV
    By yuryyuryyury in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-10-2007, 09:32 AM
  5. Save file, create .pdf, (Now delete .xls file)
    By daniels012 in forum Excel General
    Replies: 4
    Last Post: 03-30-2007, 05:14 PM

Tags for this Thread

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