Forum

Backup copy macro a...
 
Notifications
Clear all

Backup copy macro adds audit file AND a copy of template too

2 Posts
2 Users
0 Reactions
105 Views
(@webbers)
Posts: 148
Reputable Member
Topic starter
 

Okay, the code below works perfectly, however my issue is that in addition to the backup filename being saved, a copy of the template workbook is also saved.  My "template" is an xlsb file that includes a version #, as I am constantly making upgrades.  After this macro has been tweaked, the version # will again change.  The file name on "Main" cell B21 and "codes " O2 is the same file name, while is used and my original and then a copy for the back up.  The second screenshot shows my "updates" folder (path on "codes" as shown in 1st screenshot), with the template folder.  I have deleted 11 copies of this template between yesterday and today from my Updates folder.  What is wrong with my code?  I cannot figure it out.

Sub SaveAudit()
' Save file as multiple cell references

' Macro Complete - Checkmark added (to Main Sheet)
Sheet7.Range("$K$8").Value = ChrW(&H2713)

Call Insert_End
'' Call Formula_Value

Dim fname As String
Dim FPath As String
Dim backupfolder As String

' Save Active Workbook
ThisWorkbook.Save

' Save Audit file
' Save COPY of Active Workbook (with new filename)
'Path of file
FPath = Sheets("Main").Range("B7").Value
' New file name WITHOUT extension
fname = Sheets("Main").Range("B21").Text & ".xlsb"
ThisWorkbook.SaveCopyAs Filename:=FPath & "" & fname

' Save Backup file
' Save COPY of Active Workbook (with new filename)
' Path of file
backupfolder = Sheets("codes").Range("O2").Value
' New file name WITHOUT extension
fname = Sheets("Main").Range("B21").Text & ".xlsb"
ThisWorkbook.SaveCopyAs Filename:=backupfolder & "" & fname

' Save Confirmation
If Err.Number <> 0 Then
MsgBox Err.Description
Else
MsgBox "Original File saved AND a Copy of the File Saved as " & backupfolder & "" & fname
End If

Call Save_BackUp

'' ' Save Workbook & Close File (NEW Workbook) ' Deactivated until Template has been fixed!
'' ActiveWorkbook.Close SaveChanges:=True
ActiveWorkbook.Save

End Sub

2024-02-20_12-00-55.jpg

2024-02-20_12-06-42.jpg

 
Posted : 21/02/2024 1:11 pm
(@debaser)
Posts: 837
Member Moderator
 

You have two SaveCopyAs commands, so you will end up with two copies of the workbook each time, plus the original. I can't tell whether Save_Backup also creates one.

 
Posted : 21/02/2024 1:17 pm
Share: