Display alerts error

A

AWSD

Hi,

Within a Sub I have the following code fragment:

Application.ScreenUpdating = False
Application.DisplayAlerts = False
If SheetExists("Sheet3") Then Sheets("Sheet3").Delete
Application.DisplayAlerts = True

This works fine in Excel 2000 but a user using Excel 2002 has reported the
following error:

Method "display Alerts" of object '_Application' failed.

I cant see why the error is being raised. Is there a problem in 2002? Is
there a solution?
 
N

Nigel

Presumably your UDF SheetExists is causing the problem - post this code for
diagnosis.
 
A

AWSD

I don't see how as the error is specific to the Application object. Here is
the code


Function SheetExists(ByVal sName As String) As Boolean
On Error GoTo not_found
Sheets(sName).Select
SheetExists = True
Exit Function
not_found:
SheetExists = False
End Function
 
T

Tom Ogilvy

That is a peculiar error. Is this code being executed within Excel and
written in VBA?
 
A

AWSD

Yes, it is executed within Excel and written in VBA. It is executed when the
user clicks a button.
 
T

Tom Ogilvy

I would remove the selection from the SheetsExists routine.

Function SheetExists(ByVal sName As String) As Boolean
Dim sh as Object
On Error GoTo not_found
set sh = Sheets(sName)
SheetExists = True
Exit Function
not_found:
SheetExists = False
End Function
 
T

Tom Ogilvy

Nothing in the code that shouldn't work in Excel 2002. I assume the code
isn't in the sheet module for Sheet3.
 
T

Tom Ogilvy

this was a false start reply I was trying to delete and hit the send button
by mistake. Please ignore.
 
N

Nigel

I didn't either but since there was no other source of any error I just felt
seeing this might help - as I see it is very strange indeed.

Cannot offer a solution - sorry
 
A

AWSD

Thanks, I'll give it a go.

Tom Ogilvy said:
I would remove the selection from the SheetsExists routine.

Function SheetExists(ByVal sName As String) As Boolean
Dim sh as Object
On Error GoTo not_found
set sh = Sheets(sName)
SheetExists = True
Exit Function
not_found:
SheetExists = False
End Function
 
A

AWSD

No, the code is not in a sheet module.

Tom Ogilvy said:
Nothing in the code that shouldn't work in Excel 2002. I assume the code
isn't in the sheet module for Sheet3.
 

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