Jump to content
Sign in to follow this  
Twinlinked

WinActivate will not switch between excel windows

Recommended Posts

Twinlinked

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.

Share this post


Link to post
Share on other sites
Twinlinked

hey,

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

I have this at the top as well,

But i cannot even get the windows to change even if i change the code the code so the windows names are exact.

Share this post


Link to post
Share on other sites
somdcomputerguy

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


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites
Twinlinked

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.

Share this post


Link to post
Share on other sites
Jos

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 Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Twinlinked

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.

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  

×