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

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
.
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,224,818
Messages
6,181,150
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