Backup File

wichien

New Member
Joined
Mar 14, 2002
Messages
11
How Can I make Backup File with VBA Command (may be .tmp) ,Because sometime a Excel is Error . This BackupFile have to has the same PATH of Old File also . Thanks a lot.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
If Dir(ThisWorkbook.parth & "tempname.tmp") <> "" Then Kill (ThisWorkbook.parth & "tempname.tmp")
ActiveWorkbook.SaveCopyAs (ThisWorkbook.parth & "tempname.tmp")

The first is to delete the existing backup copy of the file.
Second line is the save a copy of the file to the same directory as the current file.
 
Upvote 0
Please note, for some reason, the forum converted my 1 slash into 2, so when you are copying the code, make sure you change any 2 slashes into 1.
 
Upvote 0
Hi Wichien,

No need for VBA to do this. When saving, use SaveAs and click the Options button. There is a checkbox "Always Create Backup" which will do what you want.

If you must do this through VBA, in the code module for ThisWorkbook try,

---begin VBA---
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs FileName:=ThisWorkbook.Name, CreateBackup:=True
Application.DisplayAlerts = True
End Sub
---end VBA---

This should do what you want. Please repost if you need something different.

Thanks,
Jay
 
Upvote 0

Forum statistics

Threads
1,214,556
Messages
6,120,190
Members
448,949
Latest member
keycalinc

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