Copying workbook to different folder and check for duplicate folder name

lakke2120

New Member
Joined
Aug 21, 2014
Messages
32
I have a code that copies workbook to a folder by cell value (A1) and month/year. It works fine but I need it to send a 2nd copy to another folder so I can have a back up. I would like to have the workbook copied to two separate folders with the same exact name (value in A1 and month/year). I would like to be able to check both folders to see if there are duplicate folders first and if so then overwrite. Can anyone please help. thank you

Private Sub Workbook_BeforeClose(Cancel As Boolean)

If MsgBox("Would you like to back up file?", vbYesNo) = vbYes Then _

Dim newFile As String, fName As String
' Don't use "/" in date, invalid syntax
fName = Sheets("SAP 1 PRINT ONLY").Range("A1").Value
'Change the date format to whatever you'd like, but make sure it's in quotes
newFile = fName & " " & Format$(Date, "mmmm-yyyy")
' Change directory to suit your PC, including USER NAME
ChDir _
"S:\Active Individual Programs\Manager folder\New Programs\"
ActiveWorkbook.SaveAs Filename:=newFile

End If
End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Answer found. Copy line -ActiveWorkbook.SaveAs Filename:=newFile and enter new path asfter SaveAs in quotes
 
Upvote 0

Forum statistics

Threads
1,215,020
Messages
6,122,709
Members
449,093
Latest member
Mnur

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top