我有一些文件,当我手动尝试打开它们时,会提出以下消息:
Excel在***.xlsx
中发现了不可读的内容。您想恢复工作簿的内容吗?
当我单击"是"时,它显示了以下内容:
excel能够通过修复或删除不可读的内容来打开文件。
的数据验证
删除功能:来自/xl/worksheets/sheet1.xml part part
然后我可以手动保存它,替换它,然后文件通常没有错误打开。
现在我的问题是,我想对VBA代码进行相同的操作。我准备了下面,没有运气。它带有1004错误:
Sub letshope()
WithApplication
.DisplayAlerts=False
.ScreenUpdating=False
.EnableEvents=False
.AskToUpdateLinks=False
EndWith
Set wb =Workbooks.Open(Filename:= _
"\folder***.xlsx", _
UpdateLinks:=0,Password:="password", _
IgnoreReadOnlyRecommended:=True, _
CorruptLoad:=XlCorruptLoad.xlRepairFile)
EndSub
不幸的是,网络上的每个人都建议使用CorruptLoad:=XlCorruptLoad.xlRepairFile
零件打开所有损坏的文件。不是这种情况。
任何可能有任何想法的人吗?
这是一个痛苦的过程,手动打开它们,节省它们等。
一旦我手动打开它们并按下恢复,它们都遇到了相同的错误:
错误067760_07.xml
Errors were detected in file 'XXXX.xlsx'</summary> -<removedFeatures summary="Following is a list of removed features:"> <removedFeature>Removed Feature: Data validation from /xl/worksheets/sheet1.xml part</removedFeature></removedFeatures></recoveryLog>
在函数启动之后设置Application.DisplayAlerts = False
。并在功能结束之前设置Application.DisplayAlerts=True
。
设置Application.DisplayAlert
背后的想法绕过了在Excel上工作时即将出现的任何警报。
注意:这是一个应用程序级别设置,因此将这些选项重置为其默认值很重要,否则在打开Excel时看不到警报(没有编程(。
Sub letshope()
With Application
.DisplayAlerts=False
.ScreenUpdating=False
.EnableEvents=False
.AskToUpdateLinks=False
End With
Set wb =Workbooks.Open(Filename:= _
"\folder***.xlsx", _
UpdateLinks:=0,Password:="password", _
IgnoreReadOnlyRecommended:=True, _
CorruptLoad:=XlCorruptLoad.xlRepairFile)
With Application
.DisplayAlerts=True
.ScreenUpdating=True
.EnableEvents=True
.AskToUpdateLinks=True
End With
EndSub
'
在这里相同的问题,但是这对我来说有效:
IgnoreReadOnlyRecommended:=True, CorruptLoad:=XlCorruptLoad.xlExtractData