0

e.g.

Private Sub Workbook_AfterSave(ByVal Success As Boolean)
    Beep
End Sub

This only works in "ThisWorkbook," and only in 1 spreadsheet at a time, not in my personal.xlsb file. (Inspired from here.)

4
  • You can call a macro in your personal workbook from a different workbook, but I don't recommend it. You'd be the only person who'd ever be able to use the workbook unless you had a way to add the code to be called to personal.xls. Are you really just trying to make it beep, or is the actual code more complex than this?
    – RubberDuck
    Dec 10, 2014 at 16:03
  • @RubberDuck really just make it beep. I want to know when a (sometimes) long calculation is finished. This particular event function doesn't work from my personal workbook.
    – Eliyahu
    Dec 10, 2014 at 16:04
  • Don't bother. Any code you write to do this will be longer than just calling Beep directly from the Workbook_AfterSave event.
    – RubberDuck
    Dec 10, 2014 at 16:09
  • @RubberDuck But I only want it to beep for me, not for other users who open and save the spreadsheet.
    – Eliyahu
    Dec 10, 2014 at 16:10

1 Answer 1

3
  1. Press F4 to display project properties.
  2. Name the VBAProject for your personal workbook Personal
  3. Create a subroutine that calls beep.

    Public Sub MakeItBeep
        Beep
    End Sub
    
  4. In the workbook you want to enable this in, click on Tools>>References on the menu bar.
  5. Click Browse...
  6. Find your Personal.xls file and select it. (It could be in a number of different locations, so searching the C:\ drive is usually the easiest way to go about finding it.)
  7. In the proper event of your workbook, insert this code (adjusting for module name of course).

    Personal.Module1.MakeItBeep
    

There are a couple of problems with this though, and I really don't recommend it.

  1. This is much more code and work than just calling Beep directly.
  2. This will most likely cause an error for any other user who works with the workbook. They would need to disable macros on this book. So, if there are any other macros that need to function, you can't do this.

You could use directives to work around that, but it's an awful lot of work for zero benefit. If you're still interested, I wrote a tutorial about how to use conditional compilation with a project level setting.

2
  • Very interesting! Though I have other macros in the workbook that I'd like other users to use as well...
    – Eliyahu
    Dec 10, 2014 at 16:54
  • 1
    Read the blog article I posted. You would need to conditionally compile the code then and remember to disable your beep code before sharing the workbook.
    – RubberDuck
    Dec 10, 2014 at 16:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .