View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Addin close command not working in new workbook

Personally, I think it can be a problem to save the workbook -- if the user
opens the workbook, makes some disasterous changes to the other sheet and wants
to close without saving, your code could really hurt.

I'd either delete that worksheet right before the addin needs to add it or
delete it when the workbook opens.

Option Explicit
sub Auto_Open()
application.displayalerts = false
on error resume next
thisworkbook.worksheets("what if").delete
on error goto 0
application.displayalerts = true
end sub

You could use similar code in the addin, but change this line:
thisworkbook.worksheets("what if").delete
to:
activeworkbook.worksheets("what if").delete


stewdizzle wrote:

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.


--

Dave Peterson