I'm trying to open excel files in a button_click
event. I don't encounter any errors with the first four excel files i opened, but as my macro open the fifth one, it stops and shows this run-time error:
Run-time error '-2147021892 (80070bbc)':
office has detected a problem with this file.
To help protect your computer this file cannot be opened.
Here's my code for opening excel files:
Set wb = Workbooks.Open(fileName:=fileName, UpdateLinks:=True)
Possible resolutions
Microsoft Support - Error message in Office when a file is blocked by registry policy settings gives several mechanisms for how to possibly bypass this error if you trust the document content.
Some Key Notes:
Why this is occurring
From Microsoft Support:
It appears that Office is detecting something possibly malicious with the file, such as a virus or other malware, or it's just possible that the file is corrupted. If you trust this document, proceed with opening it. Otherwise be extremely cautious to avoid an malware infection of some type.
Possibly the file seems to downloaded/copied from external source, like the internet. The below page discussed how to "unblock" such files programatically via VBA. https://answers.microsoft.com/en-us/msoffice/forum/msoffice_excel-msoffice_custom/how-to-unblock-file-using-vba/bed82938-6a57-403c-afcf-fa76a26a1ac6
See Andreas Killer's solution. he mentioned that what you clear is not a file attribute, you remove the alternate data stream "Zone.Identifier" from the file. And gives the following links:- A wiki link ... en.wikipedia.org/wiki/NTFS#Alternate_data_streams_.28ADS.29 http://vb.mvps.org/samples/Streams/
Above 2nd link to Karl E. Peterson's website provides a Streams.zip file, which contains CStreams class that needs to be imported into your project and use the KillStream function.
-Credit to Andreas Killer
Hope this helps.
I had the same problem. File was corrupted and VBA open threw that error. As a possible solution I found this (faname is a string with the path):
The important part is "CorruptLoad:= xlExtractData", that makes it possible to load the data from corrupted files without throwing this error. The other things are just there to prevent the file from doing something... together with
Just as a precaution before opening the file... if you do that do not forget to undo it before your Macro finishes like (these are my standard settings, use your own! you may find them out using Debug.Print in the Immediate Window):
Be careful what your security settings actually are and do not blindly copy these changes of settings... Also best to catch errors ("On Error ...") and terminate with resetting your previous settings.
I tried the line of code above with my "corrupted" file. The result was disasterous, (but original was backed up). All Excel worksheets (13) now have text, and All approx 93 pages of VBA code are gone. Styles=17: File size is <2000kb.
One cell with a changed cell format causes the infamous M/S error text. I don't think this is corrupt, but it may be too much programming for Excel(s).