Backup Macro Codes...

FalconBLUE

New Member
Joined
Jan 3, 2008
Messages
11
Hi everyone,

I want to backup my workbook with below codes. First of all, codes are checking backup folder whether or not. If not the folder, being created in C:\ and then being identified.

Finally, this code must saveAs active workbook. But not. Where I am making mistake I don't know. Could anyone help me to amend the macro code to work as I described?

Thank you in advance.

Code:
Sub BACKCUP()
Kayit_Yeri = "C:\Backup\"
On Error Resume Next
If Dir(Kayit_Yeri) = "" Then MkDir Kayit_Yeri
On Error Resume Next
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim Destwb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set Sourcewb = ActiveWorkbook
ActiveSheet.Copy
Set Destwb = ActiveWorkbook
With Destwb
If Val(Application.Version) < 12 Then
FileExtStr = ".xls": FileFormatNum = -4143
Else
If Sourcewb.Name = .Name Then
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
MsgBox "Your answer is NO in the security dialog"
Exit Sub
Else
Select Case Sourcewb.FileFormat
Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
Case 52:
If .HasVBProject Then
FileExtStr = ".xlsm": FileFormatNum = 52
Else
FileExtStr = ".xlsx": FileFormatNum = 51
End If
Case 56: FileExtStr = ".xls": FileFormatNum = 56
Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
End Select
End If
End If
End With

TempFilePath = Kayit_Yeri 'Application.DefaultFilePath & "\"
TempFileName = Sourcewb.Name & " " & Format(Now, "dd.mm.yyyy-hh:mm:ss")
With Destwb
.SaveAs Filename:=TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum, Password:="148264"
.Close SaveChanges:=False
End With
MsgBox "Dosyaniz Asagidaki Isimle Yedeklenmistir." & Chr(10) & TempFileName, vbInformation, "Ajandam Uyary Sistemi"
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Code:
TempFileName = Sourcewb.Name & " " & Format(Now, "dd.mm.yyyy-hh:mm:ss")
The colons in the time format are preventing your file from being saved. They are illegal characters in a file name. Either remove them like 'hhmmss' or use periods like 'hh.mm.ss'
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

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