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.
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