![]() |
Write a code with another code
How can I write a code from procedure to some Workbook's
ThisWorkbook? With procedure1 a make Workbook with a table. I need to write Auto_Close procedure to ThisWorkbook which makes some controls before I close it. Is it possible? |
Write a code with another code
http://www.cpearson.com/excel/vbe.htm
auto_close goes in a general module, not the thisworkbook module. BeforeClose is the event equivalent placed in ThisWorkbook module. -- Regards, Tom Ogilvy "JJ" wrote in message ... How can I write a code from procedure to some Workbook's ThisWorkbook? With procedure1 a make Workbook with a table. I need to write Auto_Close procedure to ThisWorkbook which makes some controls before I close it. Is it possible? |
Write a code with another code
|
Write a code with another code
Here is an example
'---------------------------------------------------------------- Sub AddWorkbookEventProc() '---------------------------------------------------------------- Dim StartLine As Long With ActiveWorkbook.VBProject.VBComponents("ThisWorkboo k").CodeModule StartLine = .CreateEventProc("BeforeClose", "Workbook") + 1 .InsertLines StartLine, _ "Dim ans" & vbCrLf & _ " ans = Msgbox( ""All OK"",vbOYesNo)" & vbCrLf & _ " If ans = vbNo Then Cancel = True" End With End Sub -- HTH RP (remove nothere from the email address if mailing direct) "JJ" wrote in message ... How can I write a code from procedure to some Workbook's ThisWorkbook? With procedure1 a make Workbook with a table. I need to write Auto_Close procedure to ThisWorkbook which makes some controls before I close it. Is it possible? |
Write a code with another code
try something like this:
=== EXAMPLE ============== Dim lLine, xCodeModule, VBE Set VBE = ThisWorkbook.VBProject Set xCodeModule = VBE.VBComponents("ThisWorkbook").CodeModule lLine = xCodeModule.CreateEventProc("BeforeClose", "Workbook") xCodeModule.InsertLines lLine + 1, "Msgbox ""before Close event""" ======= END EXAMPLE ============ and also, look at Chris Pearsons site: http://www.cpearson.com/excel/vbe.htm HTH Philip "JJ" wrote: How can I write a code from procedure to some Workbook's ThisWorkbook? With procedure1 a make Workbook with a table. I need to write Auto_Close procedure to ThisWorkbook which makes some controls before I close it. Is it possible? |
Write a code with another code
-----Original Message----- http://www.cpearson.com/excel/vbe.htm auto_close goes in a general module, not the thisworkbook module. BeforeClose is the event equivalent placed in ThisWorkbook module. -- Regards, Tom Ogilvy "JJ" wrote in message ... How can I write a code from procedure to some Workbook's ThisWorkbook? With procedure1 a make Workbook with a table. I need to write Auto_Close procedure to ThisWorkbook which makes some controls before I close it. Is it possible? . sorry I wrote auto_close. but question is if it is possible to put code with another code to BeforeClose? thanks |
All times are GMT +1. The time now is 12:15 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com