0
我有一個Excel文件與篩選記錄的宏。運行宏後,我保存並關閉文件。當我再次打開該文件時,它說,該文件已被損壞:Excel損壞與VBA排序記錄
Excel found unreadable content in '[filename].xls'.
Do you want to recover the contents of this workbook?
If you trust the source of this workbook, click Yes.
當我點擊是文件打開並查看指導我我發現下面的xml文件:
<?xml version="1.0" encoding="UTF-8" standalone="true"?>
-<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<logFileName>error050360_01.xml</logFileName>
<summary>Errors were detected in file 'C:\xxx\file.xlsb'</summary>
-<removedRecords summary="Following is a list of removed records:">
<removedRecord>Removed Records: Sorting from /xl/worksheets/sheet11.bin part</removedRecord>
</removedRecords>
</recoveryLog>
在Sheet11我有以下排序代碼:
LastRow = ActiveSheet.Range("A1").Offset(ActiveSheet.Rows.Count - 1, 0).End(xlUp).Row
Range("A3").Select
ActiveWorkbook.Worksheets("AP_PV").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("AP_PV").Sort.SortFields.Add key:=Range("A4:A" & LastRow) _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("AP_PV").Sort
.SetRange Range("A3:B" & LastRow)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
我嘗試添加範圍(「A3」)之前的狀態選擇,看看是否LASTROW> 4,排除排序,但ID沒有任何區別。
任何想法是什麼導致腐敗,以及如何避免它?