ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Delette active sheet from form button (https://www.excelbanter.com/excel-programming/434799-delette-active-sheet-form-button.html)

TimSpangler

Delette active sheet from form button
 
When I try to delete the active sheet with a button that I have on the
sheet I get an automation error. I assume it is because the button is
firing the event and I am trying to delete the sheet that the button
is on.

Is there a way to do this? Any help would be appreciated

Thanks

TIM

Mike H

Delette active sheet from form button
 
Hi,

That wouldn't cause an automation error, the sheet & button are deleted.
What else do you have in the module, post the code.

Mike

"TimSpangler" wrote:

When I try to delete the active sheet with a button that I have on the
sheet I get an automation error. I assume it is because the button is
firing the event and I am trying to delete the sheet that the button
is on.

Is there a way to do this? Any help would be appreciated

Thanks

TIM


TimSpangler

Delette active sheet from form button
 
This is what I have in the button code:

' Sub to delete the current braced wall line
Private Sub CmdBtn_DELBWL_Click()

Application.DisplayAlerts = False
If ActiveSheet.Name = "MASTER" Then
MsgBox "MASTER Sheet can not be deleted", vbCritical, "BWL
Sheet Delete Error!"
Else
ActiveSheet.Delete
Application.DisplayAlerts = True
End If

End Sub

And when the button is selected I get this:

Run-time error '-2147221080 (800401a8)':

Automation Error



On Oct 9, 3:09*pm, Mike H wrote:
Hi,

That wouldn't cause an automation error, the sheet & button are deleted.
What else do you have in the module, post the code.

Mike



"TimSpangler" wrote:
When I try to delete the active sheet with a button that I have on the
sheet I get an automation error. *I assume it is because the button is
firing the event and I am trying to delete the sheet that the button
is on.


Is there a way to do this? *Any help would be appreciated


Thanks


TIM



Mike H

Delette active sheet from form button
 
Hi,


I can replicate this if the code is in a worksheet module.

Put the sub in a general module and don't declare as private and attach the
code to your button and things should be fine.

Mike


"TimSpangler" wrote:

This is what I have in the button code:

' Sub to delete the current braced wall line
Private Sub CmdBtn_DELBWL_Click()

Application.DisplayAlerts = False
If ActiveSheet.Name = "MASTER" Then
MsgBox "MASTER Sheet can not be deleted", vbCritical, "BWL
Sheet Delete Error!"
Else
ActiveSheet.Delete
Application.DisplayAlerts = True
End If

End Sub

And when the button is selected I get this:

Run-time error '-2147221080 (800401a8)':

Automation Error



On Oct 9, 3:09 pm, Mike H wrote:
Hi,

That wouldn't cause an automation error, the sheet & button are deleted.
What else do you have in the module, post the code.

Mike



"TimSpangler" wrote:
When I try to delete the active sheet with a button that I have on the
sheet I get an automation error. I assume it is because the button is
firing the event and I am trying to delete the sheet that the button
is on.


Is there a way to do this? Any help would be appreciated


Thanks


TIM




TimSpangler

Delette active sheet from form button
 
Will do. I'll try that and get back to you.

Thanks


On Oct 9, 3:51*pm, Mike H wrote:
Hi,

I can replicate this if the code is in a worksheet module.

Put the sub in a general module and don't declare as private and attach the
code to your button and things should be fine.

Mike



"TimSpangler" wrote:
This is what I have in the button code:


' Sub to delete the current braced wall line
Private Sub CmdBtn_DELBWL_Click()


* * Application.DisplayAlerts = False
* * If ActiveSheet.Name = "MASTER" Then
* * * * MsgBox "MASTER Sheet can not be deleted", vbCritical, "BWL
Sheet Delete Error!"
* * Else
* * * * ActiveSheet.Delete
* * * * Application.DisplayAlerts = True
* * End If


End Sub


And when the button is selected I get this:


Run-time error '-2147221080 (800401a8)':


Automation Error


On Oct 9, 3:09 pm, Mike H wrote:
Hi,


That wouldn't cause an automation error, the sheet & button are deleted.
What else do you have in the module, post the code.


Mike


"TimSpangler" wrote:
When I try to delete the active sheet with a button that I have on the
sheet I get an automation error. *I assume it is because the button is
firing the event and I am trying to delete the sheet that the button
is on.


Is there a way to do this? *Any help would be appreciated


Thanks


TIM



TimSpangler

Delette active sheet from form button
 
OK. VB isn't really my thing, I am winging this right now. I took it
out of the worksheet and put it in the workbook but how do I get the
code attached to the button now? Do I us a Call from the worksheet
button event?



On Oct 9, 3:58*pm, TimSpangler wrote:
Will do. *I'll try that and get back to you.

Thanks

On Oct 9, 3:51*pm, Mike H wrote:



Hi,


I can replicate this if the code is in a worksheet module.


Put the sub in a general module and don't declare as private and attach the
code to your button and things should be fine.


Mike


"TimSpangler" wrote:
This is what I have in the button code:


' Sub to delete the current braced wall line
Private Sub CmdBtn_DELBWL_Click()


* * Application.DisplayAlerts = False
* * If ActiveSheet.Name = "MASTER" Then
* * * * MsgBox "MASTER Sheet can not be deleted", vbCritical, "BWL
Sheet Delete Error!"
* * Else
* * * * ActiveSheet.Delete
* * * * Application.DisplayAlerts = True
* * End If


End Sub


And when the button is selected I get this:


Run-time error '-2147221080 (800401a8)':


Automation Error


On Oct 9, 3:09 pm, Mike H wrote:
Hi,


That wouldn't cause an automation error, the sheet & button are deleted.
What else do you have in the module, post the code.


Mike


"TimSpangler" wrote:
When I try to delete the active sheet with a button that I have on the
sheet I get an automation error. *I assume it is because the button is
firing the event and I am trying to delete the sheet that the button
is on.


Is there a way to do this? *Any help would be appreciated


Thanks


TIM




All times are GMT +1. The time now is 01:10 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com