writing a macro using a macro

johnwayne
06-16-2008, 03:00 PM
I am using a macro which creates a new workbook and want this workbook to not ask to save when it is later closed by the user. I have done this previously by writing the following sub into the Workbook code area:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Saved = True
End Sub

However, I can't find any way to write this macro into the new workbook I create, or basically create a macro using a macro.

Anyone know how to do this, or another way to prevent it from asking to save?

thanks.

Cas
06-16-2008, 03:43 PM
Hi johnwayne (or should we call you Duke?), welcome to the forum! :)

We were just discussing something very similar in this thread (http://www.xtremevbtalk.com/showthread.php?t=297457). In post #4, Colin provided this link (http://www.eng-tips.com/faqs.cfm?fid=110) to an example which includes adding code to a dynamically created module using the Extensibility Reflection library.

Good luck! :)

johnwayne
06-17-2008, 07:42 AM
Thanks! I figured there was something already somewhere but I was having trouble searching for it since the words in my search phrases generally show up in any excel vba problem!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum