Jump to content

WinActivate will not switch between excel windows


Recommended Posts

hello,

I am trying to get AutoIT to select all the cells on one worksheet and then paste the formatting in those cells in a different worksheet.

The sheets are in different workbooks so they appear in two different excel windows.

The code i am using is:

WinActivate("Microsoft Excel - template")
WinWaitActive("Microsoft Excel - template")

Send("^{pgup 13}")

Send("^a") ; select all
Send("^c") ; copy

WinActivate("Microsoft Excel - MSR")
WinWaitActive("Microsoft Excel - MSR")

Send("^a") ; past
Send("^v")

The "template" window name is to remain the same. but the "MSR" window name will have different text that follows the letters "MSR" depending on which sheet i am updating.

When i run it i am able to get Auto IT to activate the last excel window but that is it.

Any help would be greatly appreciated.

Thanks

A.

Link to comment
Share on other sites

Try 2, that should match all cases of "Micosoft Excel - MSR"

ok so i simplified my code to make sure i have things right

Opt("WinTitleMatchMode", 3)     ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase


WinActivate("Microsoft Excel - 1")
WinWaitActive("Microsoft Excel - 1","",5)

Send("sheet 1")

WinActivate("Microsoft Excel - 2")
WinWaitActive("Microsoft Excel - 2","",5)


Send("sheet 2")

That is my entire script.

I have 2 blank excel files - 1 worksheet in each

I have run the Opt with condition 1,2,3, and 4

when i run the script:

If the last excel window selected is "1" then "1" is activated and "Sheet1" is written in the highlighted cell, then after 5sec "sheet2" is written in the same cell.

If the last excel window selected is "2" then after 5Sec "sheet1 is written in the script in my Auto IT editor. Then "2" is activated and "sheet 2 is written in the last activated cell.

I don't understand why the correct windows are not being activated, is it possible i am missing a piece of code?

Thanks Again

A.

Link to comment
Share on other sites

  • Developers

This works for me in Win7/excel 2007:

Opt("WinTitleMatchMode", 3)     ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase


WinActivate("Book1")
WinWaitActive("Book1","",5)

Send("sheet 1")

WinActivate("Book2")
WinWaitActive("Book2","",5)


Send("sheet 2")

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

This works for me in Win7/excel 2007:

Opt("WinTitleMatchMode", 3)     ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase


WinActivate("Book1")
WinWaitActive("Book1","",5)

Send("sheet 1")

WinActivate("Book2")
WinWaitActive("Book2","",5)


Send("sheet 2")

wow ok maybe my naming convention was wrong i removed "microsoft excel - " from the WinActivate command and it seems to work a little better.

Opt("WinTitleMatchMode", 1)     ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase


WinActivate("1")
WinWaitActive("1","",5)

Send("sheet 1")

WinActivate("2")
WinWaitActive("2","",5)


Send("sheet 2")

it now works correctly as long as "1" was the last window from excel to be activated..

any ideas?

A.

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