Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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?



  #3   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default 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
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Write a code with another code

Try Chip's web site for information.
http://www.cpearson.com/excel/vbe.htm

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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?





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 156
Default 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?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
could someone write me a VB code? thanks Morgan New Users to Excel 6 March 10th 10 01:20 PM
write macro code nishkrish Excel Worksheet Functions 0 April 2nd 09 09:17 PM
Write a code by code Excel Discussion (Misc queries) 1 March 23rd 05 02:34 PM
How can i write TSR code A-Design Excel Programming 5 September 29th 04 05:26 PM
Using VBA to Write VBA code SB Excel Programming 10 January 23rd 04 02:01 PM


All times are GMT +1. The time now is 02:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"