I've been unable to reproduce your exact issue. Using Microsoft.Office.Interop.Excel
if I try to open a password protected workbook that is already open, I get the following message:
This is how I'm opening the file:
wb = wbs.Open(Filename:=Location, Password:="password", Notify:=False, IgnoreReadOnlyRecommended:=True)
This is what I would expect, but you're saying isn't happening.
As a side note, I don't think the Notify
property works as expected; even with Notify:=False
it still raises the notification.
The main issue you've got is the when using Microsoft.Office.Interop.Excel
all of the file opening logic is handled by the Excel.Application
instance rather than your application. For example, if you don't provide a password it will ask for one, rather than throwing an exception. This is useful in some cases, but for automating tasks it's a bit annoying as without any feedback you can't write proper logic control.
I would recommend you look into using something like EPPlus to handle your Excel file reading/writing. Not only is it less resource intensive (you don't have to spin up an Excel application instance) it also throws exceptions when the file needs a password, or when it's being used by another user, which allows you to handle all these different situations in your application and minimalise the amount of user interaction that's required.
Open
which alter the behaviour. E.g.IgnoreReadOnlyRecommended
,ReadOnly
,Notify
. – WSC