Excel Ribbon sometimes changes when window is activated
Excel Ribbon sometimes changes when window is activated
Hello, In some script I have “WinActivate, Inventory.xlsm” followed by “WinWaitActive, Inventory.xlsm”. Often, when running this (maybe once every 5-10 times) the Ribbon tab somehow gets changes from “Home” to “File” and this completely misses up the rest of the script. I have been adding a message box in different areas of the script to determine where this is going wrong. It seems that if I have this message box right after WinWaitActive, Inventory.xlsm the Excel file always opens correctly on the home tab after clearing the MsgBox. Is it possible that the Excel file is not ready to work after it becomes active and if so is there a way to make sure that it is ready other than a time delay? I tried replacing the message box with Sleep 500 and it did not fix the problem. Any ideals here? I don’t know if it matters but there are a couple different Excel files running in one instance of Excel. Thank you
Re: Excel Ribbon sometimes changes when window is activated
I had no trouble with the following, but this does not necessarily apply to how your script works-- what commands are being used after the activation, etc.
If you are using WinWaitActive immediately after the program is run, then it could cause an issue (though it's still recommended), because the window might still not be ready for input immediately. I have seen many programs with windows like that. In some cases, a short sleep is then still needed. Related wisdom.
The following script did work.
If you post your script, it would help with the debugging.
Code: Select all
F3::
SoundBeep, 1500, 20
WinActivate, Book1.xlsx
SendInput 4{Enter}
Return
The following script did work.
Code: Select all
F3::
file = Book1.xlsx
SoundBeep, 1000, 30
Run, %TEMP%\%file%
WinWaitActive, %file% ahk_exe EXCEL.EXE,, 10
If ErrorLevel
MsgBox, 48, Error, The window did not become active.
SoundBeep, 1500, 30
SendInput {Text}92
SendInput {Enter}
Return
- tank
- Posts: 2855
- Joined: 28 Sep 2013, 22:15
- Facebook: charlie.simmons.7334
- Google: ttnnkkrr
- GitHub: ttnnkkrr
- Location: Irving TX
- Contact:
Re: Excel Ribbon sometimes changes when window is activated
so some thoughts of an idiot.
things to insure your script is consistent.
but im an idiot with little experience on this subject
things to insure your script is consistent.
- is there a shortcut excel key combo to activate home?
- is there cell selected or none. sending keys when not selected. wonder what would happen if not
- have you considered using COM
but im an idiot with little experience on this subject
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
https://www.facebook.com/ahkscript.org
If you have forum suggestions please submit a pull request
Check Out WebWriter
Thanks Tank
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
https://www.facebook.com/ahkscript.org
If you have forum suggestions please submit a pull request
Check Out WebWriter
Thanks Tank

Re: Excel Ribbon sometimes changes when window is activated
Those are all great points and suggestions!
https://autohotkey.com/board/topic/69033-basic-ahk-l-com-tutorial-for-excel/
There are also lots of posts with Excel COM examples.
https://autohotkey.com/board/topic/69033-basic-ahk-l-com-tutorial-for-excel/
There are also lots of posts with Excel COM examples.
Re: Excel Ribbon sometimes changes when window is activated
Thank you Tank... Your ideal to have some error handling to recover when things go wrong seems like a good way to deal with this. A Alt+H key shortcut key would generally bring up the home tab unless the"File" window is selected in which case it brings up a "Help" window. Let me explore some of the COM options you mention.
Re: Excel Ribbon sometimes changes when window is activated
There is interesting undocumented feature with ribbon menus
https://www.autohotkey.com/boards/viewtopic.php?t=38505
https://www.autohotkey.com/boards/viewtopic.php?t=38505
- tank
- Posts: 2855
- Joined: 28 Sep 2013, 22:15
- Facebook: charlie.simmons.7334
- Google: ttnnkkrr
- GitHub: ttnnkkrr
- Location: Irving TX
- Contact:
Re: Excel Ribbon sometimes changes when window is activated
when you have something coded feel free to post it and we can work on making it bullet proof.. my goal is to help you learn but when i see code i generally get a bit less vague.
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
https://www.facebook.com/ahkscript.org
If you have forum suggestions please submit a pull request
Check Out WebWriter
Thanks Tank
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
https://www.facebook.com/ahkscript.org
If you have forum suggestions please submit a pull request
Check Out WebWriter
Thanks Tank

Who is online
Users browsing this forum: Arsonistic, bassemand, Bing [Bot], Google [Bot], gvieira and 59 guests