When I open an Excel 2007 workbook with macros, I get the following error:
Excel found unreadable content in {FILENAME}. Do you want to recover the contents of this workbook?
I wonder if it might be the following macro. I added the ActiveSheet.Unprotect
portion and made changes to the .SaveAs TempFilePath & "\" & TempFileName & FileExtStr, FileFormat:=FileFormatNum
portion (though I don't remember exactly what they are.
This macro exports one sheet in the workbook, then unprotects it, copies and pastes values only and then closes it. This works fine but when I go save or reopen the main workbook I get the "unreadable" error.
'Working in Excel 97-2013
Sheets("Calculation").Select
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim Destwb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set Sourcewb = ActiveWorkbook
'Copy the sheet to a new workbook
ActiveSheet.Copy
Set Destwb = ActiveWorkbook
'Determine the Excel version and file extension/format
With Destwb
If Val(Application.Version) < 12 Then
'You use Excel 97-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'You use Excel 2007-2013
FileExtStr = ".xlsx": FileFormatNum = 51
End If
End With
'Change all cells in the worksheet to values if you want
With Destwb.Sheets(1).UsedRange
Application.CutCopyMode = False
ActiveSheet.Unprotect
.Cells.Copy
.Cells.PasteSpecial xlPasteValues
.Cells(1).Select
End With
Application.CutCopyMode = False
'Save the new workbook and close it
TempFilePath = Sheets("Calculation").Range("N5").Value
TempFileName = Range("N4").Value
With Destwb
.SaveAs TempFilePath & "\" & TempFileName & FileExtStr, FileFormat:=FileFormatNum
.Close SaveChanges:=False
End With
MsgBox "You can find the new file in " & TempFilePath
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub