I am writing a program to clean excel files from empty rows and columns, i started from my own question Fastest method to remove Empty rows and Columns From Excel Files usin
Concerning your solution, are you sure that it will not work with anything, that is not the password? Something like this:
Public Function wb_get_workbook(ByVal sFullName As String) As Workbook
Dim sFile As String
Dim wbReturn As Workbook
sFile = Dir(sFullName)
On Error Resume Next
Set wbReturn = Workbooks(sFile)
If wbReturn Is Nothing Then
Application.AskToUpdateLinks = False
Set wbReturn = Workbooks.Open(sFullName, , , , "ThisIsDefinitelyAPasswordThatNooneHasUsed681")
End If
On Error GoTo 0
Set wb_get_workbook = wbReturn
End Function
Will also throw an error, if it is password protected, and if it is not, then it would not care about the password you are providing. I am trying in VBA, but in C# you use the Excel Application object, so it should not be different.