VBA Code that backups when opening worksheet

Alexander K

New Member
Joined
Oct 13, 2014
Messages
16
Hi

I have written a VBA code that backups the excel worksheet on the 3rd monday of the month but it doesnt work and i doing something wrong.

Code:
Private Sub Workbook_Open()
'Backup

If TODAY() = (TODAY() - Day(TODAY()) + 32 - Weekday(TODAY() - Day(TODAY()) - 1)) Then
            
        ChDir _
        "L:\LOG20 Spares Planning\Van Stocks Control\Van Stock Profiles\Generic Regional Profiles\Profile Backups"
        ActiveWorkbook.SaveAs Filename:= _
        "L:\LOG20 Spares Planning\Van Stocks Control\Van Stock Profiles\Generic Regional Profiles\Profile Backups\300 STYLE GRP PROFILES B1.xlsm" _
        , FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=True
    
    Else
End If


End Sub

Can anyone help
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
In VBA, the equivalent for today() is date, so maybe change all in your code. I haven't checked hte formulas/logic but thats all I can see/say for now
Code:
Private Sub Workbook_Open()
    'Backup
    If Date = (Date - Day(Date) + 32 - Weekday(Date - Day(Date) - 1)) Then
            ChDir _
            "L:\LOG20 Spares Planning\Van Stocks Control\Van Stock Profiles\Generic Regional Profiles\Profile Backups"
            ActiveWorkbook.SaveAs Filename:= _
            "L:\LOG20 Spares Planning\Van Stocks Control\Van Stock Profiles\Generic Regional Profiles\Profile Backups\300 STYLE GRP PROFILES B1.xlsm" _
            , FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=True
        Else
    End If
End Sub
 
Last edited:
Upvote 0
That doesnt seem to work maybe i am not using the right code for VBA.

Basically every Monday i want it to make a backup, and when its made 4 backups it, starts again and saves over the first out of the four backups and so on.

So there is only ever 4 backups does that make sense?
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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