Hi,
We can open an excel fir ok using Ole and the following code (PB2019R2):
OleObject MyOle,wkb
MyOle = CREATE OleObject
MyOle.ConnectToNewObject('excel.application')
//Here we can add code that makes Excel not show up (MyOle.Application.Visible = false)
wkb = MyOle.Application.Workbooks.Open("c:\NoPassword.xlsx")
MessageBox("wkb.HasPassword",wkb.HasPassword)
and this will show False for the HasPassword variable.
When doing the same for a file that has a password, it works and shows Excel's "Enter Password" window.
But what we would like to do is to check if the file is password protected or not - that's all. The reason for this is that we don't want users to save spreadsheets with passwords to the database where we store documents.
Any help on this would be great.
Thanks,
ktp
thank you for your reply. We tried that but didn't find how to pass the right parameters to the Open command.
We tried e.g. the following
//From Microsoft documentation
// https://docs.microsoft.com/en-us/office/vba/api/excel.workbooks.open
// expression.Open (FileName, UpdateLinks, ReadOnly, Format, Password, WriteResPassword, //IgnoreReadOnlyRecommended, Origin, Delimiter, Editable, Notify, Converter, AddToMru, Local, CorruptLoad)
// and in our case we had
//UpdateLinks = 0 is for External references (links) will not be updated when the workbook is opened.
//ReadOnly = FALSE
//Format = 5 is for Nothing
//Password = "***" a dummy password
wkb = MyOle.Application.Workbooks.Open("m:\pass.xlsx",0,true,5,"***")
but this gives "Error calling external function Open" error.
Do you know the right way to call the Open method?
Kari
If you are sure that the call is wrong try to specify all parameters of the Open function.