Application.displayalerts issue

CMIIandExcel

Board Regular
Joined
Sep 4, 2009
Messages
190
Hi all

I am having a problem when using application.displayalerts and it has me scratching my head a bit.

I am using this to supress the alert when deleting a worksheet:

Code:
Application.DisplayAlerts = False
Debug.Print Application.DisplayAlerts
sh.Delete
Application.DisplayAlerts = True

When I hover over display alerts it shows true (after the initial change) however the debug prints it as false. I get the alert so it is not working.

to further complicate things if i run the identical code from an excel file located on my USB drive I dont have the problem, but when the excel file is on our network it occurs.

Any thoughts?

I have found a number of references to simular issues but not one with a clear answer

Thanks in advance

Mike
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Can't see a reason why it wouldn't work, except if the file on the network drive is either shared or read only !!
Otherwise it should work.
 
Upvote 0
Hi Michael

Thanks for the reply:

Files are not readonly or shared.

I have done some further tests and the issue seems to lay with where the file which is being manipulated is located i.e.

Excel app - USB drive
Excel File - USB drive
Works fine

Excel app - Network
Excel File - USB drive
Works fine

Excel app - Network
Excel File - Network
Fails

Excel app - USB Drive
Excel File - Network
Fails

I have tried these test on mine and another persons PC and I had the same results.

Any other thoughts?

Mike
 
Upvote 0
For context here is the full code of the procedure

Code:
Private Sub UnlockAndVisibleWorksheets()
Dim sh As Worksheet
  For Each sh In fWorkBook.Worksheets
    DoEvents
    If sh.ProtectContents Or sh.ProtectDrawingObjects Or sh.ProtectScenarios Then
      sh.Unprotect GLOBAL_PASSWORD
    End If
    If sh.Visible <> xlSheetVisible Then
      sh.Visible = xlSheetVisible
      If fOptimise And Not sh.Name = "Validation" Then
        Application.DisplayAlerts = False
        sh.Delete
        Application.DisplayAlerts = True
      End If
    End If
  Next sh
End Sub

All of the code is within a class module

Mike
 
Upvote 0
Thanks Michael,

Anyone else got any ideas? I have found a number of threads relating to it but no answers.

Mike
 
Upvote 0
Solved

I had numerous application objects and the displayAlerts wasnt always being applied against the application which held the excel file being manipulated in all cases.


odd how the location of the file affected which application object the display alerts was applied against.


Mike
 
Upvote 0

Forum statistics

Threads
1,215,061
Messages
6,122,921
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top