VBA:文件有时不保存

时间:2016-11-03 15:48:48

标签: excel vba save-as

此代码使用“xlExtractData”选项打开.XLSX文件,然后使用相同的文件名和路径保存它。

Application.DisplayAlerts = False
Set wb = Workbooks.Open(filename:=myPath & myFile, UpdateLinks:=0, CorruptLoad:=xlExtractData)

' Do not show the "This file already exists prompt"
Application.DisplayAlerts = False

' Save the repaired file
wb.SaveAs filename:=myPath & myFile, AccessMode:=xlExclusive, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False, ConflictResolution:=xlLocalSessionChanges

' Close the saved file
wb.Close

它适用于大多数文件(有数百个文件)但它随机不适用于某些文件。在这些情况下,它会显示“无法访问文件”的错误。

为什么它适用于某些文件而不适用于其他文件,即使是随机的?

0 个答案:

没有答案