mercredi 3 juillet 2019

Malfunctional Auto-Backup Code using Checkbox in VBA

I'm modifying a Gantt chart excel template I found online by Vertex42 for added functionality.

One of these modifications is a checkbox inside a sheet called "Config" that, when ticked, creates a backup of the Gantt chart whenever the document is opened.

For some reason, I cannot get this simple task to work.

I've tried using both the Form control and ActiveX control check boxes, with different error messages. As far as I can tell, the Form controls are unrecommended, so I'm using the code below in the ThisWorkbook excel object, based on what I've seen online.

Private Sub Workbook_open()
    If Sheets("Config").OLEObjects("AutoBackupCheckbox").Object.Value = True Then
        backupfilename = ActiveWorkbook.Name & " - backup " & Date & ".xlsm"
        ActiveWorkbook.SaveAs (backupfilename)
    End If
End Sub

This code is getting me the error message

Run-time error '1004':

Application-defined or object-defined error

Any ideas?

Aucun commentaire:

Enregistrer un commentaire