thisworkbook.save error not handled as expected

drummer_jon

New Member
Joined
Oct 20, 2020
Messages
1
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hey MrExcel community! First up I have to express my thanks to the community at large for enabling me to develop a basic understanding of VBA over the years. This is my first post, because it's the first issue I've had which hasn't already been answered!

I have a fully automated large Excel file which once an hour pulls in data from different places and saves itself to make this data available to others. Most of the time it works flawlessly, but once in a while the line "thisworkbook.save" hard fails with a system dialog message such as this:

201019 Error Message.JPG


Now clearly the reason for the fail is evident, but what I don't understand is why the dialog box appears at all. Please can someone point me in the direction of better handling system dialog boxes like this one? I had thought that either ".displayalerts = false" or "on error resume next" would allow me to log this error without seeing a dialog box which requires user interaction. I'm using a desktop version of Excel 365 on Windows 10.

With a bit of fault finding I can recreate the issue using only the following code in a shiny new Excel file saved on a tiny Virtual Hard Drive that is almost full.

VBA Code:
Sub SaveFile()

On Error Resume Next
Application.DisplayAlerts = False

    ThisWorkbook.Save
    
    If Err.Number <> 0 Then
        '<...code here which silently logs error and carries on back to the calling sub...>
    End If
    
End Sub

THINGS I'VE TRIED

- This behaviour happens on multiple machines that run the same version of Excel 365.
- However, in Excel 2010 this error message DOES NOT appear, and the error handler works as expected.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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