Jump to content

Winactivate doesn't work


Recommended Posts

I want to make an Excel window active. So I use this code:

$excel="Microsoft Excel - 2005 Part D Seminars.xls"
winactivate($excel)
winwaitactive($excel)

But when I run it, the Excel window doesn't come up, and the debugger tells me that it's hanging at winwaitactive($excel).

This is such a basic thing to do, and I've made scripts before that use winActivate without any problems. What am I doing wrong?

Link to comment
Share on other sites

But when I run it, the Excel window doesn't come up, and the debugger tells me that it's hanging at winwaitactive($excel).

Check the return code of winactivate() - see help file. I guess, that the window title is wrong. Use "AutoIT Window Info" tool to get the correct window title.

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Check the return code of winactivate() - see help file. I guess, that the window title is wrong. Use "AutoIT Window Info" tool to get the correct window title.

Cheers

Kurt

<{POST_SNAPBACK}>

No, winactivate() returned 1.
Link to comment
Share on other sites

No, winactivate() returned 1.

<{POST_SNAPBACK}>

I just tested your code on my system (W2k and Excel 2003). It works perfectly with the latest beta (.62).

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

$excel="Microsoft Excel - 2005 Part D Seminars.xls" ; this creates a handle

winactivate($excel) ; this is activating a handle

winwaitactive($excel) ; this is waiting for a handle

$excel is a win-handle

8)

EDIT

maybe you want this

winwaitactive("Microsoft Excel - 2005 Part D Seminars.xls")

8)

<{POST_SNAPBACK}>

That's not correct.

$excel="Microsoft Excel - 2005 Part D Seminars.xls" does NOT create a handle. It makes a variable that is set to the text string to the right of the equal sign. Then, winwaitactive($excel) uses that variable to pass the text string to the winwaitactive() function.

But on the chance that you're correct, I deleted $excel and put in the text string. It still didn't activate Excel, and winactivate() still returned 1.

Link to comment
Share on other sites

@Valuater,

I think:

$excel=WinGetHandle("Microsoft Excel - 2005 Part D Seminars.xls") ; this creates a handle

@sigil,

Okay, so you gave up on the use of a variable for now...

Are these the only lines of code that you are working with?

winactivate("Microsoft Excel - 2005 Part D Seminars.xls")
winwaitactive("Microsoft Excel - 2005 Part D Seminars.xls")
Do you have any options set via "AutoItSetOption"?

Are you debugging this in a script by itself or as part of a larger script?

Grasping at straws here......

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

Link to comment
Share on other sites

Are these the only lines of code that you are working with?

winactivate("Microsoft Excel - 2005 Part D Seminars.xls")
winwaitactive("Microsoft Excel - 2005 Part D Seminars.xls")
Do you have any options set via "AutoItSetOption"?

Are you debugging this in a script by itself or as part of a larger script?

Grasping at straws here......

<{POST_SNAPBACK}>

Those are the only two lines of code. I had AutoItSetOption("trayicondebug",1), but I took that out. Still nothing. I have no idea why a trivial function call is failing to perform.

Again, the window title is cut-and-pasted from the Autoit Window Info tool.

Link to comment
Share on other sites

wow - okay

Are you running it from SciTE or by double clicking on a *.au3 file (or from a complied script)?

Try:

AutoItSetOption ("WinTitleMatchMode", 2)

WinActivate("Microsoft Excel")

WinWaitActive("Microsoft Excel")

More grasping at straws.... restart system... reinstall AutoIt... boot computer out of window....

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

Link to comment
Share on other sites

wow - okay

Are you running it from SciTE or by double clicking on a *.au3 file (or from a complied script)?

Try:

AutoItSetOption ("WinTitleMatchMode", 2)

WinActivate("Microsoft Excel")

WinWaitActive("Microsoft Excel")

<{POST_SNAPBACK}>

That works. Hm. It only works if I have no other Excel files open, even when I change the string to "Microsoft Excel - 2005", which would make it unique.

Thank you for getting me this far.

Link to comment
Share on other sites

As you know --- "Microsoft Excel - 2005" --- should work!

Want to keep chasing this rabbit? It is up to you...

What editor are you making your scripts in, Notepad, SciTE or other.

Could it be messing with spaces? <<< more straws

If you are willing - run this script from the help file and see if your full title shows up in the list.

(I know, it should be the same as the spy window - but something is not working as expected.)

$var = WinList()

For $i = 1 to $var[0][0]
; Only display visble windows that have a title
  If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then
    MsgBox(0, "Details", "Title=" & $var[$i][0] & @LF & "Handle=" & $var[$i][1])
  EndIf
Next

Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then 
    Return 1
  Else
    Return 0
  EndIf

EndFunc

...or maybe the hard way:

AutoItSetOption("WinTitleMatchMode", 4)

$handle = WinGetHandle("Microsoft Excel - 2005 Part D Seminars.xls")

If @error Then MsgBox(4096, "Error", "Could not find the correct window")

WinSetState ($handle, "", @SW_RESTORE)

edit typo

edit2 .... or maybe @SW_SHOWDEFAULT

Edited by herewasplato

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

Link to comment
Share on other sites

How about?:

$excel='"Microsoft Excel - 2005 Part D Seminars.xls"'

The single quotes cause the double quotes to become part of the string...

...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
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...