Worksheet Delete method's dialog box

X

xlmaven

The Microsoft documentation states that the delete method for a
worksheet object issues a boolean False if a user clicks Cancel on the
dialog box that gets generated warning that data may be lost if the
worksheet is deleted. How can the return value from this dialog box
be examined in VBA? I get compile errors when I try examine
worksheetname.Delete directly.
 
J

Jim Thomlinson

So you are deleting a sheet through code. When the code executes the user
confirmation dialog shows and the user decides whether to delete the sheet or
not.

After this is complete why not just check for the existence of the sheet
with a function something like this...

Public Function SheetExists(SName As String, _
Optional ByVal Wb As Workbook) As Boolean
'Chip Pearson
On Error Resume Next
If Wb Is Nothing Then Set Wb = ThisWorkbook
SheetExists = CBool(Len(Wb.Sheets(SName).Name))
End Function
 
X

xlmaven

So you are deleting a sheet through code. When the code executes the user
confirmation dialog shows and the user decides whether to delete the sheetor
not.

After this is complete why not just check for the existence of the sheet
with a function something like this...

Public Function SheetExists(SName As String, _
                     Optional ByVal Wb As Workbook) As Boolean
'Chip Pearson
    On Error Resume Next
    If Wb Is Nothing Then Set Wb = ThisWorkbook
    SheetExists = CBool(Len(Wb.Sheets(SName).Name))
End Function
--
HTH...

Jim Thomlinson





- Show quoted text -

Jim,

Thanks for your reply. My concern is more fundamental--I am just
curious about how to get at the boolean value that the documentation
states is returned by the delete method.
 
J

Jim Thomlinson

Since you do not directly spawn the dialog you would need to get a handle to
it somehow. IMO that is more work than it's worth.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top