Resolved [VSTO] Can I control the event on save?

asdasd2221212

New member
Joined
Jul 4, 2021
Messages
1
Programming Experience
1-3
hello,

I am making a module using Excel VSTO.

When the user saves, i want to Save Data to specific DataBase.

currently, i did make button when user click button (add-in to excel) save data to DataBase.
 
Solution
From what I can see, something like this should work:
VB.NET:
Private Sub ThisAddIn_Startup(sender As Object, e As EventArgs)
    Dim app As Excel.Application = Me.Application
    
    AddHandler app.WorkbookBeforeSave, New Excel.AppEvents_WorkbookBeforeSaveEventHandler(AddressOf app_WorkbookBeforeSave)
End Sub

Private Sub app_WorkbookBeforeSave(Wb As Excel.Workbook, SaveAsUI As Boolean, ByRef Cancel As Boolean)
    'your code here'
End Sub
From what I can see, something like this should work:
VB.NET:
Private Sub ThisAddIn_Startup(sender As Object, e As EventArgs)
    Dim app As Excel.Application = Me.Application
    
    AddHandler app.WorkbookBeforeSave, New Excel.AppEvents_WorkbookBeforeSaveEventHandler(AddressOf app_WorkbookBeforeSave)
End Sub

Private Sub app_WorkbookBeforeSave(Wb As Excel.Workbook, SaveAsUI As Boolean, ByRef Cancel As Boolean)
    'your code here'
End Sub
 
Solution
Back
Top