Hi All
I wonder if anybody could help me with creating a button (already done that bit ;-)) which does the following for a series of workbooks in Excel 2007 (if it could be compatible with 2003 as well that would be great, but not essential):
The Private Sub CommandButton1_Click() has to do the following:
- Save a copy of the current workbook to a directory which is the same as the current active workbook filepath plus \Log1 (extra folder)
- Names the saved file as the current filename plus "_" plus the current date formatted mmddyy
- Save again, but this time saving over the open file being saved (i.e to its present filename and location) to replace the previous version, using the original filename without date stamp.
So the idea is that this button saves a copy of the active workbook to a backup folder 'Log1' at CurrentFilePath\Log1 with original filename plus _mmddyy, leaves the open workbook unchanged, and then saves again, but this time overwrites itself to its original and present actual location on the hard disk with the same, unchanged, filename, ie. CurrentFilePath\ActiveWorkBook.Name
I get the impression this shouldn't be too complex, but my VBA skills are sorely lacking.
Any help would be hugely appreciated.
Many thanks
Daniel
Here is the best I can come up with so far:
Private Sub CommandButton1_Click()
Dim Filename As String, Filepath As String
Filename = Replace(ThisWorkbook.Name, ".xls", "")
Filepath = ThisWorkbook.Path & "\Log1\"
NewFileName = Application.GetSaveAsFilename(InitialFileName:=Filepath & Filename & " " & Format(Now(), "mmddyy") & ".xls")
If NewFileName = "FALSE" Then Exit Sub
ActiveWorkbook.SaveCopyAs Filename:=NewFileName
On Error Resume Next
ActiveWorkbook.SaveAs ThisWorkbook.FullName
End Sub
How do I get it to completely exit if I cancel at the first prompt when it brings up the 'Save As' dialog? At the moment, if I cancel here, it still prompts me for the overwrite of the original filname afterwards. Ideally I'd like it to skip this if I cancel in the first instance.
Also, if I want to get rid of the prompt for the overwrite of the original, how do I do this?
Is there anything else I should have in my code which is missing?
Many thanks for any help.
Daniel
Bookmarks