Forum Discussion

siv_arunprakash's avatar
siv_arunprakash
Contributor
7 years ago
Solved

How to open a password protected excel workbook in TestComplete?

I used the following JavaScript:

 

var Excel= Sys.OleObject("Excel.Application");

Excel.Workbooks.Open(filename, 0, false, 1, "password");

 

This script worked, But if I set the "password" string in a variable of type password and I pass it to function Excel.Workbooks.Open(); TestComplete doesn't decrypt the password variable. 

 

How do I decrypt the password variable or pass it into Open function and in TestComplete docs they mention passing it using only SetText or Keys but that doesn't help in this case. 

  • You can also do this:

    Project.Variables.password.DecryptedValue

     

    This will return the Decrypted value of your password variable.

  • baxatob's avatar
    baxatob
    7 years ago

     

    .DecryptedValue - it's amazing! :) I am surprised why it is not documented...

6 Replies

  • baxatob's avatar
    baxatob
    Community Hero

    If you can't avoid using a password type variable, you can use some workaround: type your password somewhere using SetText (or Keys) method and then get it from there as a string:

     

    e.g. using Notepad:
    
    workaround = Sys.Process("notepad").Window("Notepad").Window("Edit")
    workaround.Keys(Project.Variables.yourPasswordVariable)
    Log.Message(workaround.wText)
      
    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      You can also do this:

      Project.Variables.password.DecryptedValue

       

      This will return the Decrypted value of your password variable.

      • baxatob's avatar
        baxatob
        Community Hero

         

        .DecryptedValue - it's amazing! :) I am surprised why it is not documented...

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3

    Is the password protection part of the test?  I would try finding a way to make your own test copy of the workbook that isn't password protected.  It might take some data masking or cleanup but that may be easier than worrying about this password.