Sign in to follow this  
Followers 0
junkew

Clicking on msoToolbar buttons

3 posts in this topic

Getting a little bit lunatic with AU3Info getting something like "[CLASS:MsoCommandBar; INSTANCE:3]"

and then not able to click on buttons based on properties of the button I defined the following.

Still to do for powerpoint, excel, IE, MSAccess, Outlook etc. but the basic logic is described below how to get a toolbar object from MSOffice applications and then retrieving all kinds of properties of a button on the toolbar.

Have MSWord open for example to work

;Reference an MSOffice application
$msoAppObjName= "Word.Application"
$msoAppObjClass= "[CLASS:OpusApp]"

;Get the MSOffice application (assumes its running only 1 instance)
$msoApp=objGet("",$msoAppObjName)

;Just some information to see if we did get an object
consolewrite("Count:" & $msoApp.Documents.Count & @crlf)
consolewrite("CmdBarCount: " & $msoApp.commandbars.count & @crlf)

;## Example ##
;Just iterate over the first 25 visible bars if they not exist exit loop
winactivate($msoAppObjClass,"")
$i=1
while $i<25 
    $cName = "[CLASS:MsoCommandBar; INSTANCE:" & $i & "]"
    $pos=controlgetpos($msoAppObjClass,"",$cName)
    if isarray($pos) <> 1 then 
        ExitLoop
    endif
;   $handle=controlgethandle($msoAppObjClass,"",$cname)
;   if $handle="" Then
;       ExitLoop
;   EndIf
    $myBar = getMSOBar($msoApp,$msoAppObjClass, $cName)
    if $myBar <> -1 Then
        consolewrite("Controlcount:" & $mybar.controls.count & @crlf)
        for $j=1 to $myBar.controls.count
            consolewrite("  ")
            consolewrite(" caption:" & $mybar.controls($j).caption)
            consolewrite(" enabled:" & $mybar.controls($j).enabled)
            consolewrite(" id:" & $mybar.controls($j).id)
            consolewrite(" caption:" & $mybar.controls($j).caption)
            consolewrite(" left:" & $mybar.controls($j).left)
            consolewrite(" top5:" & $mybar.controls($j).top)
            consolewrite(" width:" & $mybar.controls($j).width)
            consolewrite(" height:" & $mybar.controls($j).height)
            consolewrite(" tooltiptext:" & $mybar.controls($j).tooltiptext)
            consolewrite(" visible:" & $mybar.controls($j).visible)
            consolewrite(" descriptiontext:" & $mybar.controls($j).descriptiontext & @crlf)
        
            ;Some fun with the mouse
        if $mybar.controls($j).visible = -1 then
            $left=$mybar.controls($j).left + ($mybar.controls($j).width/2)
            $top =$mybar.controls($j).top + ($mybar.controls($j).height/2) 
            mousemove(int($left),int($top),5)
        endIf
        next

    EndIf

    $i=$i+1
wend
;## End Example ##

;The actual function
;$msoApp = Object reference
;$msoClass = The window class to search control in
;$ctrlName = The [CLASS:MsoCommandBar; INSTANCE:##] description
func getMSOBar($msoApp, $msoClass, $ctrlName)
    $pos=controlgetpos($msoClass,"",$ctrlName)
    if isarray($pos) Then
    ;consolewrite( $i & "POS: " & $pos[0] & "," & $pos[1] & " SIZE: " & $pos[2] & "," & $pos[3] & @crlf )
    ;consolewrite("CmdBarCount: " & $msoApp.commandbars.count & @crlf)
        for $j=1 to $msoApp.commandbars.count-1
            if $msoApp.commandbars($j).visible = -1 Then
                $left = $msoApp.commandbars($j).left
                $top = $msoApp.commandbars($j).top
                $width = $msoApp.commandbars($j).Width
                $height = $msoApp.commandbars($j).height
                
                if ($width = $pos[2]) and ($height = $pos[3]) then 
                    consolewrite($cName & " Match: " & $j &  "," & $left & "," & $top & "," & $width & "," & $height & @crlf )
                    Return $msoApp.commandbars($j)
                endif
            EndIf
        next
    EndIf
    return -1
endfunc

Share this post


Link to post
Share on other sites



Getting a little bit lunatic with AU3Info getting something like "[CLASS:MsoCommandBar; INSTANCE:3]"

and then not able to click on buttons based on properties of the button I defined the following.

Still to do for powerpoint, excel, IE, MSAccess, Outlook etc. but the basic logic is described below how to get a toolbar object from MSOffice applications and then retrieving all kinds of properties of a button on the toolbar.

Have MSWord open for example to work

;Reference an MSOffice application
$msoAppObjName= "Word.Application"
$msoAppObjClass= "[CLASS:OpusApp]"

;Get the MSOffice application (assumes its running only 1 instance)
$msoApp=objGet("",$msoAppObjName)

;Just some information to see if we did get an object
consolewrite("Count:" & $msoApp.Documents.Count & @crlf)
consolewrite("CmdBarCount: " & $msoApp.commandbars.count & @crlf)

;## Example ##
;Just iterate over the first 25 visible bars if they not exist exit loop
winactivate($msoAppObjClass,"")
$i=1
while $i<25 
    $cName = "[CLASS:MsoCommandBar; INSTANCE:" & $i & "]"
    $pos=controlgetpos($msoAppObjClass,"",$cName)
    if isarray($pos) <> 1 then 
        ExitLoop
    endif
;   $handle=controlgethandle($msoAppObjClass,"",$cname)
;   if $handle="" Then
;       ExitLoop
;   EndIf
    $myBar = getMSOBar($msoApp,$msoAppObjClass, $cName)
    if $myBar <> -1 Then
        consolewrite("Controlcount:" & $mybar.controls.count & @crlf)
        for $j=1 to $myBar.controls.count
            consolewrite("  ")
            consolewrite(" caption:" & $mybar.controls($j).caption)
            consolewrite(" enabled:" & $mybar.controls($j).enabled)
            consolewrite(" id:" & $mybar.controls($j).id)
            consolewrite(" caption:" & $mybar.controls($j).caption)
            consolewrite(" left:" & $mybar.controls($j).left)
            consolewrite(" top5:" & $mybar.controls($j).top)
            consolewrite(" width:" & $mybar.controls($j).width)
            consolewrite(" height:" & $mybar.controls($j).height)
            consolewrite(" tooltiptext:" & $mybar.controls($j).tooltiptext)
            consolewrite(" visible:" & $mybar.controls($j).visible)
            consolewrite(" descriptiontext:" & $mybar.controls($j).descriptiontext & @crlf)
        
        ;Some fun with the mouse
        if $mybar.controls($j).visible = -1 then
            $left=$mybar.controls($j).left + ($mybar.controls($j).width/2)
            $top =$mybar.controls($j).top + ($mybar.controls($j).height/2) 
            mousemove(int($left),int($top),5)
        endIf
        next

    EndIf

    $i=$i+1
wend
;## End Example ##

;The actual function
;$msoApp = Object reference
;$msoClass = The window class to search control in
;$ctrlName = The [CLASS:MsoCommandBar; INSTANCE:##] description
func getMSOBar($msoApp, $msoClass, $ctrlName)
    $pos=controlgetpos($msoClass,"",$ctrlName)
    if isarray($pos) Then
;consolewrite( $i & "POS: " & $pos[0] & "," & $pos[1] & " SIZE: " & $pos[2] & "," & $pos[3] & @crlf )
;consolewrite("CmdBarCount: " & $msoApp.commandbars.count & @crlf)
        for $j=1 to $msoApp.commandbars.count-1
            if $msoApp.commandbars($j).visible = -1 Then
                $left = $msoApp.commandbars($j).left
                $top = $msoApp.commandbars($j).top
                $width = $msoApp.commandbars($j).Width
                $height = $msoApp.commandbars($j).height
                
                if ($width = $pos[2]) and ($height = $pos[3]) then 
                    consolewrite($cName & " Match: " & $j &  "," & $left & "," & $top & "," & $width & "," & $height & @crlf )
                    Return $msoApp.commandbars($j)
                endif
            EndIf
        next
    EndIf
    return -1
endfunc
I have Word 2007 open Windows XP SP3 and I get error:

CODE
D:\Scripts\msoToolbar.au3 (9) : ==> Variable must be of type "Object".:

consolewrite("Count:" & $msoApp.Documents.Count & @crlf)

consolewrite("Count:" & $msoApp^ ERROR

Share this post


Link to post
Share on other sites

obviously its not getting the object of msword (I cannot check as I have word 2003)

$msoApp=objGet("",$msoAppObjName)

you could try to change to

$msoApp=objCreate($msoAppObjName)

;If not visible command like this should be tried

$msoApp.Visible=-1 ;TRUE

Share this post


Link to post
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
Sign in to follow this  
Followers 0