1. Kari Paukku
  2. PowerBuilder
  3. Friday, 16 October 2020 05:56 AM UTC

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

 

 

René Ullrich Accepted Answer Pending Moderation
  1. Friday, 16 October 2020 08:35 AM UTC
  2. PowerBuilder
  3. # 1

With XLSX (but not XLS!) you may try another option:

XLSX files are ZIP compressed files. You may try to uncompress the XLSX file. In my encrypted XLSX I can see files EncryptionInfo and EncryptedPackage in the root directory of the XLSX (ZIP) file.

HTH,

René

 

Comment
There are no comments made yet.
René Ullrich Accepted Answer Pending Moderation
  1. Friday, 16 October 2020 06:18 AM UTC
  2. PowerBuilder
  3. # 2

Hi Kari,

you could try to open the excel file and specify a wrong or empty password in Open function. If the file is password protected I think you will get an OLERuntimeError exception that you can catch.

But check if you can distinguish from other kind of errors.

HTH,

René

Comment
  1. Kari Paukku
  2. Friday, 16 October 2020 07:32 AM UTC
Rene,



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
  1. Helpful
  1. René Ullrich
  2. Friday, 16 October 2020 07:36 AM UTC
The reason for "Error calling external function Open" may be all kind of errors. Also that the password was not correct.

If you are sure that the call is wrong try to specify all parameters of the Open function.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.