LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Excel ActiveX password encryption

Solved!
Go to solution

I have a password protected workbook and would like to unlock it with activeX.  How would one enter the password for a protected workbook problematically if excel is waiting for that password and not allow the vi to continue??

0 Kudos
Message 1 of 7
(2,566 Views)
Solution
Accepted by topic author mmcneary

Capture.PNG


aputman
LabVIEW 2017
LabVIEW Programming
0 Kudos
Message 2 of 7
(2,537 Views)

I have a same problem which I still couldn't figure out why the program still waiting for user to key-in password manually instead of it automatically get the password from my vi.

I attached together my VI snippet for you reference.

Firstly, the VI run and check whether the file exist or not.

If not, it will create the file and protect it using password "123". Then the program close. So now the excel is protected with password of 123.

 

Then I run the program again, and now since the file is already existed, the program will proceed to open the password protected file. But when it try to open the excel file, it stuck at waiting password from user. Is there anyway to make this password 'unprotect' process pragmatically in LabVIEW?

I've tried to use invoke node as suggested by aputman, but maybe i'm doing it wrongly. Can anyone correct me?

 

Cheers,

Ridz

0 Kudos
Message 3 of 7
(1,792 Views)

I think you are using the wrong VI to open the file. You are using the "Create Report" for a file that already exists, is there an "Open Report" VI you can use. Sorry I do not use the Report Generation Toolkit.

 

@Bob_Schor will hopefully chime it, as he is an expert in this field.

 

mcduff

0 Kudos
Message 4 of 7
(1,778 Views)

I used the Worksheet -> Unprotect method and you are using Workbook -> Unprotect.  These are two separate actions, so make sure you are using the proper one.  


aputman
LabVIEW 2017
LabVIEW Programming
0 Kudos
Message 5 of 7
(1,773 Views)

Yes, I'm aware of this and did try out using workbook node to unprotect the excel workbook, but it seems that is not the one.

I did some digging and find out that the password '123' that I set in "Save Report to File.vi" below....

 

Excel Test.png

 

is actually go to a reference of Excel._Workbooks and not Excel._Workbook. However, when I retrieve the ActiveX reference using "Excel Get ActiveX Reference.vi" as below...

Open Protect Excel File.png

 

It return a reference of Excel._Workbook, not Excel._Workbooks. This is why it does not work when we try to unprotect it because it is a wrong reference!

I figured this out when reading the ActiveX documentation here = https://docs.microsoft.com/en-us/office/vba/api/excel.workbooks.open

As you can see, Workbooks.Open method takes an argument that consist of password, thus in LabVIEW, the invoke node will looks like this:

 

Workbooks invoke node.png

 

So my question now, is there any vi in the report generation that can return the ref to Excel._Workbooks so that I can use the ActiveX open method to unprotect the excel file by filling up the password argument (as indicated in picture above).

I can't unbundle the report in or report out wire since it is not allowed to unbundle the class in my vi.

So I'm stuck at the moment.

Hope someone can help.

-Ridz-

 

0 Kudos
Message 6 of 7
(1,756 Views)

Are you sure that is the password that you want to use?  You want to prevent the file from being opened entirely without the password?  In Excel 2010, this is equivalent to File -> Save As and clicking the Tools button -> General Options and setting the Password to open.  

2019-02-27_9-09-52.png

If this is what you want, the Excel Get ActiveX References returns an Application reference.  Use this with a property node to get the Workbooks object.


aputman
LabVIEW 2017
LabVIEW Programming
0 Kudos
Message 7 of 7
(1,734 Views)