Opening and Repairing Excel file using VBA

DJhuffman

New Member
Joined
Apr 16, 2019
Messages
17
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?
 

Some videos you may like

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Logit

Well-known Member
Joined
Aug 31, 2016
Messages
3,333
.
Try replacing :

On Error GoTo Err_Open

With :

On Error Resume Next
 

DJhuffman

New Member
Joined
Apr 16, 2019
Messages
17
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!
 

Logit

Well-known Member
Joined
Aug 31, 2016
Messages
3,333
.
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" .
 

Watch MrExcel Video

Forum statistics

Threads
1,102,134
Messages
5,484,935
Members
407,475
Latest member
Dix_Fix

This Week's Hot Topics

  • Finding issue in If elseif else with For each Loop
    Finding issue in If elseif else with For each Loop I have tried this below code but i'm getting in Y column filled with W005. Colud you please...
  • MsgBox Error
    Hi Guys, I have the below error show up when i try and run my macro in File1 but works fine if i copy and paste the same code into file2. [ATTACH...
  • CELL FORMAT - IF CONDITION
    My Cell Format is [B]""0.00" Cr". [/B]But in the cell, it is showing 123.00 for editing. (123 is entry figure). (Data imported from other...
  • Show numbers nearly the same
    Is this possible. I have a number that can change very time eg 0.00001234 Then I have a lot of numbers 0.0000001, 0.0000002, 0.00000004...
  • Please i need your help to create formula
    I need a formula in cell B8 to do this >>if b1=1 then multiply ( cell b8) by 10% ,if b1=2 multiply by 20%,if=3 multiply by 30%. Thank you in...
  • Got error while adding column and filter
    Got error while adding column and filter In column Z has some like "Success" and "Error". I want to add column in AA if the Z cell value is...
Top