Hi,
ich habe ein Problem und zwar tritt der Laufzeitfehler 52 auf, wenn ich meine VBA Datei auf einem SharePoint speichere/ablege und sie dann anschließend öffnen möchte. Leider weiß ich keine Antwort darauf, die Datei ist übrigens schreibgeschützt.
Option Explicit
Sub DailyBackup()
Dim FSO As Object, fsoFolder As Object
Set FSO = CreateObject("scripting.filesystemobject")
Dim buPath As String
Dim fPath As String
'Checks full filepath. If the word Backup appears (inlcuding its name or any directory), no backup is saved.
'We don't need backups of backups of backups
If InStr(ThisWorkbook.FullName, "Backup") Then Exit Sub
buPath = ThisWorkbook.Path & "\Daily Backup"
'If the directory does not yet exist in the same directory as the workbook, the condition is satisfied and the directory is created
If Len(Dir(buPath, vbDirectory)) = 0 Then
MkDir buPath
End If
Set fsoFolder = FSO.GetFolder(buPath)
fPath = buPath & "\Backup - [" & Year(Date) & "-" & Month(Date) & "-" & Day(Date) & "].xlsm"
'Backups are named after the date. If one already exists with the same date information then a second one is not saved.
If Len(Dir(fPath, vbNormal)) = 0 Then
ThisWorkbook.SaveCopyAs fPath
End If
'Once the Backup folder has reached 100MB, a warning message is displayed to the User every time the workbook is opened.
If fsoFolder.Size > (10 ^ 8) Then
MsgBox "The 'Daily Backup' folder has surpassed 100MB. Consider deleting older files or moving them to another directory to prevent this message.", vbExclamation, "Backup Folder Size Warning"
End If
End Sub
|