Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Execute code on Save

Posted on 2011-09-30
4
Medium Priority
?
241 Views
Last Modified: 2012-05-12
How do I call a macro each time I save a workbook?
0
Comment
Question by:fitaliano
  • 2
4 Comments
 
LVL 12

Expert Comment

by:kgerb
ID: 36895629
Put this in the workbook module.  Change MyMacro to the name of the procedure you want to call.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Call MyMacro
End Sub

Open in new window


Kyle
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 36895633
0
 

Author Comment

by:fitaliano
ID: 36903374
The suggested code doesn't work.  I put a breakpoint and it skips the routine.  Any suggestion?
0
 
LVL 12

Accepted Solution

by:
kgerb earned 2000 total points
ID: 36903552
did you put it in the "workbook" module?  It won't work if you put it in a normal module.

code for workbook events goes in here
Kyle
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question