Application.OnTime says it cannot execute (existing, Public, inside-of-a-module) Sub

geoffm

New Member
Joined
Dec 11, 2017
Messages
6
I setup this sub to have my file backed up every 5 minutes.
When I execute the module manually it works as expected but after the 5 minutes timeout I get an error message saying it cannot run [workbook path][sub name]
I looked at examples on the web and I can't find what I did wrong.
My sub is inside a module. Here is the code:

Code:
Public Sub SilentBackup()
    
    If Not Left(ActiveWorkbook.Path, 8) = "https://" Then
        strBackupPath = ActiveWorkbook.Path & "\Backups\" 'Nom du dossier local dans lequel mettre le backup
    Else
        Exit Sub
    End If
    
    strBackupFileName = Left(ThisWorkbook.Name, (InStrRev(ThisWorkbook.Name, ".", -1, vbTextCompare) - 1)) & "_backup_" & Format(Now(), "yyyy-mm-dd_hhmm") & ".xlsm"

    ActiveWorkbook.SaveCopyAs strBackupPath & strBackupFileName
    If Len(Dir(strBackupPath & strBackupFileName)) = 0 Then
        Debug.Print Now & " : Tentarive de backup échouée"
    Else
        Range("dateDernierBackup").Value = Date
        Debug.Print Now & " : Backup réussi: " & strBackupPath & strBackupFileName
    End If
    
    Application.OnTime EarliestTime:=Now + Range("SilentBackupDelai"), Procedure:="SilentBackup"
        
End Sub
Any clue?
 

geoffm

New Member
Joined
Dec 11, 2017
Messages
6
The message I get says "impossible to run file!sub, maybe it is not available in this workbook or macros are deactivated"
 

Forum statistics

Threads
1,082,607
Messages
5,366,587
Members
400,904
Latest member
ndaines meriabi

Some videos you may like

This Week's Hot Topics

Top