Sign in to follow this  
Followers 0
dnf999

Case and Winactivate not working..

3 posts in this topic

Hi All,

I'm having a problem where I cannot get specific Excel sheets to open and then text pasted to them dependent on the For loop value. i.e. if the value is below 10000 then open up a specific .xlsm sheet and run a macro, if the value is above 10000 then open a different .xlsm sheet and then run a macro.

But when I try and run the below part of the script, it only opens the first .xlsm sheet and does not go to the other sheets, even though the $i value > 10000

For $i = 1 to 40000 Step 1

    Select 
        Case $i <= 10000
            WinActivate("SHR_RA_Transactions_00001_10000") 
            Send("!{F8}")
            Send("{ENTER}") 
        Case $i >=10001 and $i<= 20000
            WinActivate("SHR_RA_Transactions_10001_20000") 
            Send("!{F8}")
            Send("{ENTER}") 
        Case $i >=20001 and $i<= 30000
            WinActivate("SHR_RA_Transactions_20001_30000") 
            Send("!{F8}")
            Send("{ENTER}") 
        Case $i >=30001 and $i<= 40000
            WinActivate("SHR_RA_Transactions_30001_40000") 
            Send("!{F8}")
            Send("{ENTER}") 
    EndSelect

    Next

Please can anybody tell me if I am doing anything incorrect with the WinActiviate statement (I've tried WinWait but that doesn't work either..)

Thanks!!

Share this post


Link to post
Share on other sites



Hi All,

I'm having a problem where I cannot get specific Excel sheets to open and then text pasted to them dependent on the For loop value. i.e. if the value is below 10000 then open up a specific .xlsm sheet and run a macro, if the value is above 10000 then open a different .xlsm sheet and then run a macro.

But when I try and run the below part of the script, it only opens the first .xlsm sheet and does not go to the other sheets, even though the $i value > 10000

For $i = 1 to 40000 Step 1

    Select 
        Case $i <= 10000
            WinActivate("SHR_RA_Transactions_00001_10000") 
            Send("!{F8}")
            Send("{ENTER}") 
        Case $i >=10001 and $i<= 20000
            WinActivate("SHR_RA_Transactions_10001_20000") 
            Send("!{F8}")
            Send("{ENTER}") 
        Case $i >=20001 and $i<= 30000
            WinActivate("SHR_RA_Transactions_20001_30000") 
            Send("!{F8}")
            Send("{ENTER}") 
        Case $i >=30001 and $i<= 40000
            WinActivate("SHR_RA_Transactions_30001_40000") 
            Send("!{F8}")
            Send("{ENTER}") 
    EndSelect

    Next

Please can anybody tell me if I am doing anything incorrect with the WinActiviate statement (I've tried WinWait but that doesn't work either..)

Thanks!!

You can test @error after WinActivate() to see if the correct window was activated before proceeding. Most likely your window specification is failing, so WinActivate() is doing nothing, leaving the currently active window unchanged. Check the windows with the AU3Info.exe window info tool to see if you really have the title, or just a document name, etc.

If you get the handles to those windows before starting the loop and use those instead of titles it will be much more reliable.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

... I cannot get specific Excel sheets to open ...

~~~

... it only opens the first .xlsm sheet and does not go to the other sheets, ...

Welcome to the forum.

Are these worksheets within one file or different spreadsheets files?

> ... it only opens the first .xlsm worksheet and does not go to the other worksheets, ...

or

> ... it only opens the first .xlsm spreadsheet and does not go to the other spreadsheets, ...

or

.................?


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

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