ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Insert code by code (https://www.excelbanter.com/excel-programming/312483-insert-code-code.html)

Filips Benoit

Insert code by code
 
Dear All,

I create a new excel workbook from a template by using
Selection.PasteSpecial so the code in the template is not copied. But i want
some new code in the new workbook!

Is it possible to insert code ( workbook_Before_close) in the new workbook.

Filip



Frank Kabel

Insert code by code
 
Hi
siehe:
http://www.cpearson.com/excel/vbe.htm

--
Regards
Frank Kabel
Frankfurt, Germany

"Filips Benoit" schrieb im Newsbeitrag
...
Dear All,

I create a new excel workbook from a template by using
Selection.PasteSpecial so the code in the template is not copied. But

i want
some new code in the new workbook!

Is it possible to insert code ( workbook_Before_close) in the new

workbook.

Filip




Bob Phillips[_6_]

Insert code by code
 
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


--

HTH

RP

"Filips Benoit" wrote in message
...
Dear All,

I create a new excel workbook from a template by using
Selection.PasteSpecial so the code in the template is not copied. But i

want
some new code in the new workbook!

Is it possible to insert code ( workbook_Before_close) in the new

workbook.

Filip






All times are GMT +1. The time now is 05:18 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com