Change to VB code to ignore error when saving file

scarlett3

Board Regular
Joined
Jan 21, 2005
Messages
73
Office Version
  1. 365
Platform
  1. Windows
I have an Excel file A on my server that reads live data. Via a macro, a different Excel file B is opened every 20 minutes, specific cell ranges are copied over from the original file A and then Excel file B is closed.

This stops working when, presumably, someone else is querying Excel file B (via asp script) as I receive a 'can't save Excel file B because the file is read-only' error message. The more serious issue is that the code in Excel file A is paused because of the 'read-only' error so I don't have the live data stored in Excel file A after the error message.

I'm using a simple [ActiveWorkbook.Save ActiveWindow.Close] code to save and close Excel file B.

Is there a way to change the code such that the 'read-only' error is ignored and the code in Excel file A continues to run regardless of any save/close error in Excel file B?

Thanks
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Try this:
Code:
Sub ign_err()
'First part of your code here...
On Error GoTo err_handler
    ActiveWorkbook.Save 'etc etc
    'etc etc
GoTo noerror
err_handler: MsgBox "There was an error saving Excel file B!", 48

noerror:
On Error GoTo 0
'Rest of your code here...
End Sub
 
Last edited:
Upvote 0
Thanks for your help, sykes.

However, it sticks on the message box.

These files are not monitored in real-time on my server, so this needs to run automatically without user intervention.
 
Upvote 0
Oh, I thought you wanted a message...
Being lazy (for a quick response) just ditch the messagebox, then - thus:
Code:
Sub ign_err()
'First part of your code here...
On Error GoTo err_handler
    ActiveWorkbook.Save 'etc etc
    'etc etc
err_handler: On Error GoTo 0
'Rest of your code here...
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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