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?
 

Logit

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

Forum statistics

Threads
1,082,023
Messages
5,362,725
Members
400,687
Latest member
jomelprototype

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top