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
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.
Sub Test()
Dim C As New CStreams
Dim i As Integer
With C
.FileName = "C:\test.txt"
For i = 1 To .Count - 1
Debug.Print .KillStream(i)
Next
End With
End Sub
-Credit to Andreas Killer
Hope this helps.