Jump to content

OK button on Excel 2010 password box


dhhcdad
 Share

Recommended Posts

Under Win7 64-bit, in Excel 2010, the OK button (or the CANCEL button, for that matter) on the Password box does now show any control information when checked via Au3Info_x64.exe. Can see the control info for the password box, though.

Anyone know why?

More importantly, in the absence of control information, how to automate the clicking of the OK button?

Much appreciate your help.

Link to comment
Share on other sites

Without seeing the window/info, I would suggest using WinGetClassList(), and then use some logic to get the handles of all the controls (some identifiers to, like the control text)

Sometimes the window info tool only get's the parent object, and can't focus on the children. The above will work around this.

example

#include <Array.au3>
$hWin = "YOUR HANDLE OR TITLE"
$sClassList = WinGetClassList($hWin)
$aClassList = StringSplit($sClassList,@CRLF,2)
_ArraySort ($aClassList)
_ArrayDelete ($aClassList, 0 )
Dim $aClassAndHandle[UBound($aClassList)][3]
$sPreviousClass = ""
$iCounter = 0
For $i = 0 To UBound ($aClassList) - 1
If $aClassList[$i]<>$sPreviousClass Then
$iCounter = 1
$sPreviousClass = $aClassList[$i]
Else
$iCounter += 1
EndIf
$aClassAndHandle[$i][0] = ControlGetHandle ($hWin, "", $aClassList[$i] & $iCounter)
$aClassAndHandle[$i][1] = ControlGetText ($hWin, "", $aClassAndHandle[$i][0])
$aClassAndHandle[$i][2] = $aClassList[$i]
Next
_ArrayDisplay ($aClassAndHandle)

Another solution, since buttons are easier to get information of by text, is to use the buttons text.:

ControlGetHandle ($hwnin,"","[CLASS:Button; TEXT:TEXTOFBUTTON]")

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Welcome to AutoIt and the forum!

What do you want to do with Excel (open a password protected worksheet ...) so that you get the password box?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Hi water. Thanks for the welcome. Thanks for supporting the forum. This is my first post, but I've read and learned a lot from this forum.

The goal is simply to supply the password and click on the OK button--so that the password box can be suppressed.

Abode Acrobat Reader also puts up a simple password box (seemingly identical to the password box that Excel 2010 uses), and Au3Info_x64.exe has no problem picking up the control info for the OK button there. Something must be different with Excel 2010.

Link to comment
Share on other sites

Yeah, but when does the password box pop up? When you try to open the Excel workbook?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Exactly!

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Why you don't use the _ExcelBookOpen function, where you can easily insert the password as a parameter without messing with buttons and controls?

Well, the trouble is that the script is not in position to initiate the opening of the workbook, nor does it have the path and name of the workbook at hand.

Link to comment
Share on other sites

And who is going to enter the password? The user who opened the workbook or your script?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

But why do you then set a password at all?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Without seeing the window/info, I would suggest using WinGetClassList(), and then use some logic to get the handles of all the controls (some identifiers to, like the control text)

Sometimes the window info tool only get's the parent object, and can't focus on the children. The above will work around this.

example

#include <Array.au3>
$hWin = "YOUR HANDLE OR TITLE"
$sClassList = WinGetClassList($hWin)
$aClassList = StringSplit($sClassList,@CRLF,2)
_ArraySort ($aClassList)
_ArrayDelete ($aClassList, 0 )
Dim $aClassAndHandle[UBound($aClassList)][3]
$sPreviousClass = ""
$iCounter = 0
For $i = 0 To UBound ($aClassList) - 1
If $aClassList[$i]<>$sPreviousClass Then
$iCounter = 1
$sPreviousClass = $aClassList[$i]
Else
$iCounter += 1
EndIf
$aClassAndHandle[$i][0] = ControlGetHandle ($hWin, "", $aClassList[$i] & $iCounter)
$aClassAndHandle[$i][1] = ControlGetText ($hWin, "", $aClassAndHandle[$i][0])
$aClassAndHandle[$i][2] = $aClassList[$i]
Next
_ArrayDisplay ($aClassAndHandle)

Another solution, since buttons are easier to get information of by text, is to use the buttons text.:

ControlGetHandle ($hwnin,"","[CLASS:Button; TEXT:TEXTOFBUTTON]")

I took your code and made slight modifications, as follows, and ran it:

#include <Array.au3>
$hWin = "Password"

while 1

winwaitactive($hWin)
$sClassList = WinGetClassList($hWin)
$aClassList = StringSplit($sClassList,@CRLF,2)
_ArraySort ($aClassList)
_ArrayDelete ($aClassList, 0 )
Dim $aClassAndHandle[UBound($aClassList)][3]
$sPreviousClass = ""
$iCounter = 0
For $i = 0 To UBound ($aClassList) - 1
If $aClassList[$i]<>$sPreviousClass Then
$iCounter = 1
$sPreviousClass = $aClassList[$i]
Else
$iCounter += 1
EndIf
$aClassAndHandle[$i][0] = ControlGetHandle ($hWin, "", $aClassList[$i] & $iCounter)
$aClassAndHandle[$i][1] = ControlGetText ($hWin, "", $aClassAndHandle[$i][0])
$aClassAndHandle[$i][2] = $aClassList[$i]
Next
_ArrayDisplay ($aClassAndHandle)


wend

The result, for the Excel 2010 Password dialog box, is that the array output only shows one row that represents the EDITBX.

For comparsion, I ran the same test for an Adobe Acrobat Password dialog box, and the array output showed six rows which included both the OK and Cancel buttons as well as the static text items, etc.

Haven't tried your second suggstion yet. Will report back after. Thanks.

Link to comment
Share on other sites

Tried the ControlGetHandle method as follows:

Local $hHandle = ControlGetHandle ($hWin,"","[CLASS:Button; TEXT:OK]")
MsgBox(0, "ControlGetHandle Example", "The control handle of Button is: " & $hHandle)
 
Local $hHandle = ControlGetHandle ($hWin,"","[CLASS:Button; INSTANCE:1]")
MsgBox(0, "ControlGetHandle Example", "The control handle of Button is: " & $hHandle)

Neither managed to return the handle. It is as if the OK and CANCEL buttons do not exist on that window.

Link to comment
Share on other sites

This works for me although I would personally use the Excel COM interface.

Example:

prerequisite is that the password input dialog is visible

Unlock("yourpassword")

Func Unlock($Password)
$hwnd = WinActivate("Unprotect Sheet","")
ControlFocus($hwnd,"","[CLASS:EDTBX]")
ControlSetText($hwnd,"","[CLASS:EDTBX;]",$Password)
ControlSend($hwnd,"","[CLASS:EDTBX]","{TAB 1}{ENTER}")
;~ ControlSend($hwnd,"","[CLASS:EDTBX]","{TAB 2}{ENTER}") ;<==== Click cancel if require
EndFunc

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

This works for me although I would personally use the Excel COM interface.

Example:

prerequisite is that the password input dialog is visible

Unlock("yourpassword")

Func Unlock($Password)
$hwnd = WinActivate("Unprotect Sheet","")
ControlFocus($hwnd,"","[CLASS:EDTBX]")
ControlSetText($hwnd,"","[CLASS:EDTBX;]",$Password)
ControlSend($hwnd,"","[CLASS:EDTBX]","{TAB 1}{ENTER}")
;~ ControlSend($hwnd,"","[CLASS:EDTBX]","{TAB 2}{ENTER}") ;<==== Click cancel if require
EndFunc

This method worked for me also. Thanks!
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...