View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Addin close command not working in new workbook

You would need to have the addin instantiate application level events.

see Chip Pearson's page on this

http://www.cpearson.com/excel/appevent.htm


It would then need to check the workbook triggering the before close event
and make sure it is the one that needs the sheet deleted.

You could have


Private Sub WorkbookBeforeClose(Wb As Workbook, Cancel As Boolean)
if wb.name = Thisworkbook.Name then exit sub
if wb.Name = "Something" then ' some condition to check the workbook
Application.DisplayAlerts = False
wb.Sheets("What If").Delete
Application.DisplayAlerts = True
wb.Save
ThisWorkbook.Close
End if
End Sub


--
Regards,
Tom Ogilvy




"stewdizzle" wrote in message
ups.com...
I have an existing workbook (WrkBk1) that contains two sheets. I also
have an addin (addin) that inserts a new sheet into WrkBk1. When the
user is done with the workbook I want it to delete the sheet that was
added in, then save and then close both WrkBk1 and the addin. Here is
the code that I am using to initiate the activity.

Private Sub workbook_beforeclose(cancel As Boolean)
Application.DisplayAlerts = False
ActiveWorkbook.Sheets("What If").Delete
Application.DisplayAlerts = True
ActiveWorkbook.Save
End Sub

It works fine if it is saved into WrkBk1 but I can't do that I need
everything to be contained in the addin. Right now it is saved into a
module, I'm not sure if that makes a difference or not.