Opening and Repairing Excel file using VBA

DJhuffman

New Member
Joined
Apr 16, 2019
Messages
25
I'm trying to automate the processing of several files, and several of the files throw up the message:

"We found a problem with some content in 'ThisFile.xlsx'. Do you want us to try to recover as much as we can? If you trust the source of this workbook, click yes."

In order to get around this first message, I've been trying out:

Code:
Dim oWB As Workbook

On Error GoTo Err_Open

Set oWB = Workbooks.Open(ThisWorkbook.Path & "\ThisFile.xlsx", CorruptLoad:=XlCorruptLoad.xlRepairFile)

Exit Sub

Err_Open:

MsgBox Err.Number & " - " & Err.Description

Err.Clear

While this works in dodging the first prompt, a subsequent prompt involving the notice of completed repair and validation comes up, requiring me to click close (sorry, I can't get a picture at this time).

This effectively seems to break the sequence and stop the code from subsequent commands. Is there a way to code to bypass this prompt as well, effectively allowing me to move on to subsequent commands?
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
.
Try replacing :

On Error GoTo Err_Open

With :

On Error Resume Next
 
Upvote 0
Thank you for your help on this. That change seems to allow the code to move on, though the error window still persisted. I had an additional problem getting the file to save over itself without prompt, so I utilized:

Application.DisplayAlerts = False

Which apparently had the added bonus of removing the problematic window as well. Huzzah for serendipity!
 
Upvote 0
.
As you discovered the ON ERROR RESUME NEXT does not remove the error ... it is best to resolve
the issue that caused the Error Msgs to begin with.

"Application.DisplayAlerts = False" is standard programming practice. Don't forget to 'turn it back on' at the bottom
of your macro with "
Application.DisplayAlerts = True" .
 
Upvote 0

Forum statistics

Threads
1,214,825
Messages
6,121,788
Members
449,049
Latest member
greyangel23

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