Jump to content

ControlSend without control ID?


Recommended Posts

I'm trying to use ControlSend to send "^j" to a minimized instance of Excel. However, there is no control ID associated with Excel when there are no spreadsheets open.

I'm sending ctrl-J to start a VB macro within Excel, which loads and parses the newest files in the directory.

I thought this would work:

ControlSend("XLDESK", "", "", "{CTRLDOWN}j{CTRLUP}")

... and it doesn't give me any error messages, but it doesn't seem to work either.

Thanks in advance!

Link to comment
Share on other sites

"XLDESK" is the Class

"Microsoft Excel" is the title

ControlSend("title", "text", controlID, "string" [, flag])

Yeah, I realized that about 30 seconds ago then saw your response. Still doesn't work though... have any more insight into this? Thanks.

ControlSend("Excel", "", "", "^j")
Link to comment
Share on other sites

  • Moderators

ControlSend("Microsoft Excel", "", "", "^j")
...I can not test right now...
ControlSend("[CLASS:XLDESK]", "", "", "^j")
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

ControlSend("Microsoft Excel", "", "", "^j")
...I can not test right now...
Thanks, but I don't think the problem is finding the title (and I did test it; didn't work). I'm able to use ControlSend just fine with programs like Notepad, but with Microsoft Excel 2007, I can't get a control ID for the main window.

This is what Info tells me:

>>>> Window <<<<

Title: Microsoft Excel

Class: XLMAIN

Position: -8, -8

Size: 1296, 1010

Style: 0x15CF0000

ExStyle: 0x00000110

Handle: 0x00070360

>>>> Control <<<<

Class: XLDESK

Instance: 1

ClassnameNN: XLDESK1

Advanced (Class): [CLASS:XLDESK; INSTANCE:1]

ID: <------ Don't I need this to use ControlSend?

Text:

Position: -1, 175

Size: 1282, 805

ControlClick Coords: 752, 345

Style: 0x56000000

ExStyle: 0x00000000

Handle: 0x000303CA

>>>> Mouse <<<<

Position: 751, 512

Cursor ID: 2

Color: 0xA4C3EB

>>>> StatusBar <<<<

>>>> Visible Text <<<<

Status Bar

Status Bar

Ribbon

Ribbon

General

>>>> Hidden Text <<<<

Vertical

PERSONAL

Vertical

Horizontal

MsoWorkPane

Collect and Paste 2.0

MsoWorkPane

Office Clipboard

Link to comment
Share on other sites

  • Moderators

Tried that too, thanks... muttley

Thanks as in it worked?

The class there is different as well: XLMAIN

So it would be:

ControlSend("[CLASS:XLMAIN]", "", "", "^j")

Edit: Or

ControlSend("[CLASS:XLMAIN]", "", "XLDESK1", "^j")
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Thanks as in it worked?

The class there is different as well: XLMAIN

So it would be:

ControlSend("[CLASS:XLMAIN]", "", "", "^j")

Edit: Or

ControlSend("[CLASS:XLMAIN]", "", "XLDESK1", "^j")
I'm sorry, thanks as in "it didn't work but thanks anyway"... and neither did either of those... muttley
Link to comment
Share on other sites

  • Moderators

Hard to help really... as control j does nothing without the macro your using for me.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Hard to help really... as control j does nothing without the macro your using for me.

My current set-up makes Excel active, then send "^j", which activates a VB macro within Excel.

What I'm trying to do is to just sent the "^j" to a minimized instance of Excel, but apparently I need the Control ID for the main window of Excel, and there isn't one that the AutoIt Window Info tool can see.

From what I can see it doesn't matter what's being sent to Excel - I can't even send just the letter "a", but I can do it with Notepad. Is it because it's Excel 2007?

Thanks for reading this.

Link to comment
Share on other sites

From the help file under ControlSend:

The control might first need to be given focus with the ControlFocus command....

WinSetState("[CLASS:XLMAIN]", "", @SW_MINIMIZE)
Sleep(1000)
$ret = ControlFocus("[CLASS:XLMAIN]", "", "XLDESK1")
ConsoleWrite(@CR & @CR & "Excel minimized - ControlFocus returned " & $ret & @CR & @CR)
$ret = ControlSend("[CLASS:XLMAIN]", "", "XLDESK1", "^j")
ConsoleWrite(@CR & @CR & "Excel minimized - ControlSend returned " & $ret & @CR & @CR)

WinActivate("[CLASS:XLMAIN]")
Sleep(1000)
$ret = ControlFocus("[CLASS:XLMAIN]", "", "XLDESK1")
ConsoleWrite(@CR & @CR & "ControlFocus returned " & $ret & @CR & @CR)
$ret = ControlSend("[CLASS:XLMAIN]", "", "XLDESK1", "^j")
ConsoleWrite(@CR & @CR & "ControlSend returned " & $ret & @CR & @CR)
Excel minimized - ControlFocus returned 0

Excel minimized - ControlSend returned 1

ControlFocus returned 1

ControlSend returned 1

[size="1"][font="Arial"].[u].[/u][/font][/size]

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...