Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8480323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:15:51+00:00 2026-06-10T19:15:51+00:00

I am going to show a MessageBox before save workbook. I have tried with

  • 0

I am going to show a MessageBox before save workbook. I have tried with event handler Sub App_WorkbookBeforeSave() and Sub Workbook_BeforeSave but both doesn’t work! Why?

There are my Sub in addin:

Private Sub App_WorkbookBeforeSave(ByVal Wb As Workbook, _
                                   ByVal SaveAsUI As Boolean, Cancel As Boolean)
    MsgBox "Good bye! Data is save."
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    MsgBox "Good bye! Data is save."
End Sub

UPDATE

I was put them in ThisWorkbook modules belong to Microsoft Excel Objects

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T19:15:53+00:00Added an answer on June 10, 2026 at 7:15 pm

    This kind of functionality requires…

    • The code to be in ThisWorkbook module of the Add-In, OR
    • Using a class to hold the event handling code, while still kicking it off in the ThisWorkbook module

    Either way, you need to create an instance of a WithEvents Application object which, while you don’t touch the object directly after you create it, enables the events to be captured.

    I like the second option (cleaner, makes you look like a boss, etc.). Create a class and call it something. I like to call my class ImAGoodListener. In the class, include the appropriate Subs for any application events you want to use

    Public WithEvents App As Application
    
    Private Sub App_WorkbookBeforeSave(ByVal Wb As Workbook, ByVal SaveAsUI As Boolean, Cancel As Boolean)
        On Error Resume Next
        MsgBox "Good bye!"
    End Sub
    

    With the arguments, you can do cool and mischievous things like prevent the workbook from being saved…

    (I like On Error Resume Next for this so we don’t risk not allowing a user to save his/her workbook should our code go haywire)

    In the ThisWorkbook module put something like this…

    Dim objAppLis As New ImAGoodListener
    
    Private Sub Workbook_Open()
        Set objAppLis.App = Application
    End Sub
    

    This will start the event listening when your Add-In is initially opened.

    Alternatively, if you’re using CustomUI for the ribbon, you use a Ribbon Onload event to trigger the start of listening (I do this when my events are used primarily for ribbon behavior so I can easy disable listening in the CustomUI xml).

    Some other application events of use are:

    • App_SheetActivate
    • App_WorkbookActivate
    • App_WorkbookOpen
    • App_WorkbookBeforeClose
    • App_WorkbookBeforeSave

    Here’s a list of all events, but note that some of them are workbook (event handlers start with Workbook_ events which won’t work for this sort of thing.

    Chip goes into great detail about these sort of events on his site here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three table views inside a view controller (going to show/hide table views
i try to show and hide divs on click but something isnt going wel
What's going on? : The accordion is working properly, but the tabs show up
First I'm going to show you an image of what I'm trying to recreate
I'm going to deploy my Java game to show it to my friends and
I am trying to show a progress bar while my process is going on...in
I am trying to show a progress bar while my process is going on...in
I really don't know how to explain what's going on, so I'll just show
Going through happstack-lite tutorial : we build functions that have return type of ServerPart
going thru a tutorial on python lists,I tried to write a python function which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.