Code for Step 3
Sub AddWorkbookEventProc()
Dim StartLine As Long
With ActiveWorkbook.VBProject.VBComponents("ThisWorkboo k").CodeModule
StartLine = .CreateEventProc("BeforeSave", "Workbook") + 1
.InsertLines StartLine, _
"Dim ans" & vbCrLf & _
" ans = Msgbox( ""All OK"",vbOYesNo)" & vbCrLf & _
" If ans = vbNo Then Cancel = True"
End With
End Sub
--
HTH
Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
"Olaerts Ludo " wrote in
message ...
I' am starting from an open excel work- book a code. This code
contents:
Step 1: I would add a new workbook
Step 2: I would insert a commandbutton on sheet(1) that listen to a
code (e.g. a msgBox)
Step 3: I want to include a event workbook_beforeSaved (e.g. a msgBox)
Is it possible to write one code in the open workbook that do those
things
I have made step 1 succesfully:
Function CreateNewWorkbook(Optional intNumberSheets As Integer = 1)
As Workbook
Dim wkbNew As Excel.Workbook
On Error GoTo CreateNewWorkbook_Err
Set wkbNew = Workbooks.Add
Set CreateNewWorkbook = wkbNew
Application.SheetsInNewWorkbook = intNumberSheets
CreateNewWorkbook_End:
Exit Function
CreateNewWorkbook_Err:
Set CreateNewWorkbook = Nothing
wkbNew.Close savechanges:=False
Set wkbNew = Nothing
Resume CreateNewWorkbook_End
End Function
---
Message posted from http://www.ExcelForum.com/