On 15 août, 21:58, "Bob Butler" <bob_but...@cox.invalid> wrote:
> "avi" <avi...@bezeqint.net.il> wrote in message
>
> news:7461de42-4096-4404-a676-ee2a73126173@z7g2000vbp.googlegroups.com...
>
> > Hello,
>
> > I try to fire commands when active workbook is closed with a class
> > module, but without any success
>
> > Public WithEvents objSpr As Excel.Workbook
> > Public Sub objSpr_BeforeClose(Cancel As Boolean)
> > MsgBox "hkjhkhkj"
> > End Sub
>
> how are you assigning 'objSpr'? The code below starts Excel and reacts to
> the workbook close for me.
>
> Private WithEvents moXL As Excel.Application
> Private WithEvents moWB As Excel.Workbook
> Private WithEvents moWS As Excel.Worksheet
>
> Private Sub Form_Load()
> Set moXL = CreateObject("Excel.application")
> Set moWB = moXL.Workbooks.Add
> Set moWS = moWB.Worksheets(1)
> moXL.Visible = True
> End Sub
>
> Private Sub moWB_BeforeClose(Cancel As Boolean)
> MsgBox "Excel workbook is about to close"
> End Sub
Thanks, It works
Avi