Link to home
Start Free TrialLog in
Avatar of excelismagic
excelismagic

asked on

excel vba help, how to trigger workbook change event, if anycell is changed then automatically save workbook

Hi,

i need help with VBA code.

how can i have a workbook event code that whenever any cell in any worksheet of thisworkbook is changed then workbook is automatically saved.

thanks.
ASKER CERTIFIED SOLUTION
Avatar of Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj)
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You probably want to add a couple of lines to Neeraj's code so that you don't get asked about saving the workbook on every change.
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Application.EnableEvents = False
Application.DisplayAlerts = False
ThisWorkbook.Save
Application.DisplayAlerts = True
Application.EnableEvents = True

End Sub

Open in new window

@Martin
While simply saving the workbook, you won't get any alert. You get alert while you close the workbook without saving it first and you are asked to save the changes or not. Am I wrong?
Or I am missing something here?
@Excel is Magic: Ignore my post. Neeraj is correct.
Avatar of excelismagic
excelismagic

ASKER

thanks.
You're welcome!