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

geoffm

New Member
Joined
Dec 11, 2017
Messages
7
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?
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
The message I get says "impossible to run file!sub, maybe it is not available in this workbook or macros are deactivated"
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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