ktv6
ktv6

Reputation: 755

Automatical repair of number of corrupted .xlsx files via VBA script

I have a number of corrupted .xlsx files in a directory. I want to open every single file for repair and save it with the same name via VBA script.

I`ve tried following piece of code to solve this problem:

Sub ProcessFiles()
Dim Filename, Pathname As String
Dim wb As Workbook

Pathname = ActiveWorkbook.Path & "\output\"
Filename = Dir(Pathname & "*.xlsx")
Do While Filename <> ""
    Set wb = Workbooks.Open(Pathname & Filename, CorruptLoad:=xlRepairFile)
    wb.Close SaveChanges:=True
    Filename = Dir()
Loop
End Sub

But this code only repairs first file and opens windows explorer to save file manualy.

Is there a way to perform repair and save all files with the same name in the same folder automatically?

Upvotes: 0

Views: 823

Answers (2)

HardCode
HardCode

Reputation: 6756

I haven't touched VBA in years, but there is an explicit wb.SaveAs method you can call.

Upvotes: 1

Solus161
Solus161

Reputation: 65

Have you set Application.DisplayAlert = False? Your codes seems fine. You just have to turn it on later.

Upvotes: 0

Related Questions