Run-time error upon opening excel file

前端 未结 4 776
礼貌的吻别
礼貌的吻别 2021-01-07 00:02

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

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-07 00:04

    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.

提交回复
热议问题