Thanks a lot for testing that. What that indicates to me is that there is
some other factor in my code that I didn't provide that is contributing to
the symptom I'm encountering. I think I know what it might be. I hope this is
not too much data.
On the 'Lists' sheet is a command button. The command button's click event
is coded as:
Private Sub cmdBuildLists_Click()
BuildLists
End Sub
The routine BuildLists exists in the Module1 code. The BuildLists routine
manipulates data on the 'Lists' worksheet' and creates Named Ranges.
On another WS 'Budget Template' is the following macro to respond to another
command button:
'Budget Template':
Private Sub cmdMigrateWB_Click()
' Macro created 2/24/2009 by John
' This macro is called by the command button on the template
' worksheet in order to initiate the migration process or
' template update process.
If ThisWorkbook.FileFormat = xlTemplate Then
' we are obtaining the 'Lists' sheet from the previous template
CheckLists (True)
Else
MigrateWorkbook
End If
End Sub
Also in Module1 is the routine that is failing and has the following partial
logic:
Sub CheckLists(Optional tmplUpdate As Boolean = False)
' Gather some data from 'Lists' worksheet,
' prompt the user to open another template,
' verify the file that is opened is what I expect and has the correct
version ids.
' Do this:
prevValue = Application.DisplayAlerts
Application.DisplayAlerts = False
On Error Resume Next <-- BreakPoint, stops here.
Sheets.Item("Lists").Delete
On Error GoTo ErrThisSub <-- BreakPoint. Message displayed?
Application.DisplayAlerts = prevValue
'copy the template from the other workbook.
' close the other workbook.
So I think the issue is that VBA does not like me to delete the sheet that
has a macro that is calling another macro in Module1.
So to avoid this issue, I have a question. Is there a way to intercept a
command button event from a macro that is not on the sheet with the command
button. I think if I can get that code off of the sheet, I will avoid this
issue. Is there another way to do this? The other option is I just accept
that I can't step through this code to debug.
I submitted another message here for a similar issue. In that case, I was
deleting the sheet that contained the command button that called the Module1
macro.
Psudo code:
Sheet2:
Private Sub cmd_Click()
DeleteSheet
end sub
Module1:
sub DeleteSheet()
Sheet2.delete
end sub.
This seems to run fine, but after the Sheet2.delete, I couldn't enter break
mode. I need to delete those sheets, but I don't know how to do this in a
clean way. I thought in this case, I wouldn't hit the problem because I
wasn't deleting the macro that Module1 macro was trying to return to.
Any thoughts?
Thanks,
John