macros造成不可读的错误

当我用macros打开Excel 2007工作簿时,出现以下错误:

Excel在{FILENAME}中发现不可读的内容。 你想恢复这个工作簿的内容?

我不知道这是否可能是下面的macros。 我添加了ActiveSheet.Unprotect部分,并对.SaveAs TempFilePath & "\" & TempFileName & FileExtStr, FileFormat:=FileFormatNum部分进行了更改(尽pipe我不记得它们是什么。

此macros导出工作簿中的一个工作表,然后解除其保护,仅复制和粘贴值,然后closures它。 这工作正常,但是当我去保存或重新打开主要工作簿时,我得到“不可读”的错误。

 '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 

错误在这里

 If Val(Application.Version) < 12 Then 'You use Excel 97-2003 FileExtStr = ".xls": FileFormatNum = -4143 

xls的文件格式是56而不是-4143

这些是Excel 2007-2013中的主要文件格式:

 50 = xlExcel12 (Excel Binary Workbook in 2007-2013 with or without macro's, xlsb) 51 = xlOpenXMLWorkbook (without macro's in 2007-2013, xlsx) 52 = xlOpenXMLWorkbookMacroEnabled (with or without macro's in 2007-2013, xlsm) 56 = xlExcel8 (97-2003 format in Excel 2007-2013, xls)