Forum

VBA to save Audit F...
 
Notifications
Clear all

VBA to save Audit File AND copy to backup folder with path & filename in cell values

10 Posts
3 Users
0 Reactions
136 Views
(@webbers)
Posts: 147
Estimable Member
Topic starter
 

I have a macro that worked, until I attempted to add an upgrade to it.  I mean the old portion work (saving of file), but the new task is to save it in my backup folder.  It will save, but with the "template name" rather than the audit file name.

The macro adds a check box once run (there are multiple macros in this workbook.  The Insert_End marco that is call just adds the date/time that the process is complete.  Now it is copying the template name that it currently exists as (such as Word Comment Extraction Tool v165.xlsb).  I would like it to save the backup file with the IDENTICAL file name as for the Audit File (this file name is listed on "Main" sheet cell B21 (without an extension), this is 

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

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

'Save Active Workbook
ThisWorkbook.Save

'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
backupfolder = Sheets("codes").Range("O2").Text & ".xlsb"
ThisWorkbook.SaveCopyAs Filename:=backupfolder & ThisWorkbook.Name

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

Call Save_BackUp

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

End Sub

 
Posted : 03/10/2023 11:28 am
(@keebellah)
Posts: 373
Reputable Member
 

Since you're using ThisWorkbook.Name it's the name of the currenbtly active file whihc is the saved file

Instead just refer to the B2 cell text to save it as the 'original name but you have to add a dispaly alerts is false if you want to overwrite it automatically

 
Posted : 04/10/2023 2:09 am
(@webbers)
Posts: 147
Estimable Member
Topic starter
 

@Hans Hallebeek,

I made a change, and now what happens it BOTH my Audit file with the correct name generated from the cell values AND the template name show in my backup folder.  I just don't understand how to fix it, but I did make progress.

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
FPath = Sheets("codes").Range("O2").Value
' New file name WITHOUT extension
fname = Sheets("Main").Range("B21").Text & ".xlsb"
ThisWorkbook.SaveCopyAs Filename:=FPath & "" & fname

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

Call Save_BackUp

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

End Sub

 
Posted : 04/10/2023 1:23 pm
(@keebellah)
Posts: 373
Reputable Member
 

Make sure the filepaths are correct for each file.

Can you attach the template file with the values in the different sheets?

Just some dummy data is enough but it will be simpler that way.

 
Posted : 05/10/2023 1:55 am
(@keebellah)
Posts: 373
Reputable Member
 

Try using this section of the code like this, check the red text

 

' 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

 
Posted : 05/10/2023 2:24 am
(@webbers)
Posts: 147
Estimable Member
Topic starter
 

@Hans Hallebeek,

I made the modifications per your suggestion.  However, I am still encountering one challenge.  The file is saving in BOTH the individual project folder, and the back-up folder.  However the issue is that the Template (Word Comment Extraction Tool v170.xlsb) is ALSO saving in the back-up folder.  This folder should NOT be saved in the back-up folder.  How can I fix this?

2023-10-05_11-44-13.png

 
Posted : 06/10/2023 11:49 am
(@keebellah)
Posts: 373
Reputable Member
 

I'll have to read the code you have more thouroughly.

The problem lies in the file names used

 
Posted : 07/10/2023 1:59 am
(@webbers)
Posts: 147
Estimable Member
Topic starter
 

@Hans Hallebeek,

Thanks again.  I just have no clue why it is saving BOTH of these files.  I am sure it must be something simple, but I just cannot see it.

 
Posted : 07/10/2023 10:54 am
(@ishellstrike)
Posts: 1
New Member
 

Very useful thank you

 
Posted : 07/10/2023 2:17 pm
(@keebellah)
Posts: 373
Reputable Member
 

@Sherry Fow, I'm missing two macros, 

Save_BackUp

Insert_End

Since you also addres diffrente Sheets like Sheet7, Main,

 

I suggest you attach a copy of your template file and maybe that way I can make sense of all what you're trying

 
Posted : 09/10/2023 4:25 pm
Share: