Vonsteiner
New Member
- Joined
- Apr 14, 2014
- Messages
- 45
- Office Version
- 365
- Platform
- Windows
Greetings Everyone,
I hope everyone is well. I have userform code in place to save a file based on a cell value and to also save a backup file with the date added. Both of these work for the most part. Here is the code as I have it right now:
Backup Code
With the code in this order is saves both of the files in the correct place, but the backup file now has become the active workbook. If I reverse the code and have Excel save the backup first it saves both files in the Backups folder, but it does make my non-backup the active file. Is there a way to have Excel save both files correctly, but then have the non-backup file be the active workbook? Also, I have the code save the workbook after each userform using the wb.save command. Right now it would just save the non-backup. How would I include the backup being saved as well.
Michael
I hope everyone is well. I have userform code in place to save a file based on a cell value and to also save a backup file with the date added. Both of these work for the most part. Here is the code as I have it right now:
Code:
Dim wb As Workbook
Dim wbname As String
Set wb = ActiveWorkbook
wbname = ThisWorkbook.Path & "\" & _
ThisWorkbook.Worksheets("Case Information").Range("A1").Value & " MTO "
wb.SaveAs wbname
Call BackupWorkbook
Backup Code
Code:
Dim wb2 As Workbook
Dim wbname2 As String
Set wb2 = ActiveWorkbook
wbname2 = ThisWorkbook.Path & "\Backups\" & _
ThisWorkbook.Worksheets("Case Information").Range("A1").Value & " MTO " & _
Format(Now(), "dd-mm-yyyy")
wb2.SaveAs wbname2
With the code in this order is saves both of the files in the correct place, but the backup file now has become the active workbook. If I reverse the code and have Excel save the backup first it saves both files in the Backups folder, but it does make my non-backup the active file. Is there a way to have Excel save both files correctly, but then have the non-backup file be the active workbook? Also, I have the code save the workbook after each userform using the wb.save command. Right now it would just save the non-backup. How would I include the backup being saved as well.
Michael