Excel upgrade 2010 to 2016

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Chris_CH_GVA

Excel upgrade 2010 to 2016

20 Mar 2018, 10:39

Hello everyone,

I am using AHK with Excel to copy data and paste them in another program.
But since I had my Excel upgraded (not really had the choice) from 2010 version to 2016, my script does not work anymore.
Is this something that can just be changed in the .ahk file?
I am not a super user, the script was created by someone else.

Hope someone could help. Thanks a lot.
burque505
Posts: 1732
Joined: 22 Jan 2017, 19:37

Re: Excel upgrade 2010 to 2016

20 Mar 2018, 11:09

Are you free to paste the script?
Regards,
burque505
Chris_GVA
Posts: 4
Joined: 20 Mar 2018, 10:31

Re: Excel upgrade 2010 to 2016

22 Mar 2018, 03:56

Hi burque505,

Thanks for your reply.
Yes, here it is:


SetKeyDelay, 80
WinWait, Microsoft Excel - Credit Creator,
IfWinNotActive, Microsoft Excel - Credit Creator, , WinActivate, Microsoft Excel - Credit Creator,
WinWaitActive, Microsoft Excel - Credit Creator,
Sleep, 500
Send, {CTRLDOWN}f{CTRLUP}
Sleep, 500
Send, Order{ENTER}
Sleep,500
Send, {ESC}
Sleep, 500
Send, {DOWN}
Sleep, 300

Loop
{
Send, {CTRLDOWN}c{CTRLUP}
StringReplace, ClipBoard, Clipboard, `r`n, , All
If clipboard = End
Break
Else
{
Order = %Clipboard%
}

Send, {RIGHT}{CTRLDOWN}c{CTRLUP}
StringReplace, ClipBoard, Clipboard, `r`n, , All

Material = %Clipboard%

Send, {RIGHT}{CTRLDOWN}c{CTRLUP}
StringReplace, ClipBoard, Clipboard, `r`n, , All

Description = %Clipboard%

Send, {RIGHT}{CTRLDOWN}c{CTRLUP}
StringReplace, ClipBoard, Clipboard, `r`n, , All

Amount = %Clipboard%

Send, {RIGHT}{CTRLDOWN}c{CTRLUP}
StringReplace, ClipBoard, Clipboard, `r`n, , All

Reason = %Clipboard%

WinWait, SAP Easy Access,
IfWinNotActive, SAP Easy Access, , WinActivate, SAP Easy Access,
WinWaitActive, SAP Easy Access,

FileRead, ORIGSCRIPT, %A_Desktop%\Geneva Project\Credit Creator\CC1.vbs
StringReplace, NEWSCRIPT1, ORIGSCRIPT, ORDERREPLACE, %Order%, All

FileDelete, %A_Desktop%\Geneva Project\Credit Creator\CC2.vbs
FileAppend, %NEWSCRIPT1%, %A_Desktop%\Geneva Project\Credit Creator\CC2.vbs

Runwait, %A_Desktop%\Geneva Project\Credit Creator\CC2.vbs

Loop
{
IfWinNotExist, Create Credit
{

Sleep, 1000
Send, {ENTER}
}
Else
{
Break
}
}


FileRead, ORIGSCRIPT, %A_Desktop%\Geneva Project\Credit Creator\CC3.vbs
StringReplace, NEWSCRIPT1, ORIGSCRIPT, MATERIALREPLACE, %Material%, All
StringReplace, NEWSCRIPT2, NEWSCRIPT1, DESCRIPTIONREPLACE, %Description%, All
StringReplace, NEWSCRIPT3, NEWSCRIPT2, AMOUNTREPLACE, %Amount%, All
StringReplace, NEWSCRIPT4, NEWSCRIPT3, REASONREPLACE, %Reason%, All

FileDelete, %A_Desktop%\Geneva Project\Credit Creator\CC4.vbs
FileAppend, %NEWSCRIPT4%, %A_Desktop%\Geneva Project\Credit Creator\CC4.vbs


Runwait, %A_Desktop%\Geneva Project\Credit Creator\CC4.vbs


Loop
{
IfWinNotExist, Display Sales Order
{

Sleep, 1000
}
Else
{
Sleep, 500
Send, {SHIFTDOWN}{END}{SHIFTUP}
Sleep, 300
Send, ^c
Send, {F3}
Sleep, 500
Break
}
}

WinWait, Microsoft Excel - Credit Creator,
IfWinNotActive, Microsoft Excel - Credit Creator, , WinActivate, Microsoft Excel - Credit Creator,
WinWaitActive, Microsoft Excel - Credit Creator,
Sleep, 500
Send, {RIGHT}^v
Send, {DOWN}{HOME}
Sleep, 300
}

MsgBox, All Credits have been created

Return
gregster
Posts: 8989
Joined: 30 Sep 2013, 06:48

Re: Excel upgrade 2010 to 2016

22 Mar 2018, 12:00

In general, automating Excel would probably be more reliable through its COM interface, but that would require a re-write of your script.

Anyway, let's see what can be done with this script. The first thing I would check is the window title of Excel. Your script depends on a Excel window with the exact title Microsoft Excel - Credit Creator , for example here, already in the second line:

Code: Select all

WinWait, Microsoft Excel - Credit Creator
If the title you get now, in Excel 2016, is for example Microsoft Excel 2016 - Credit Creator, then it will wait forever. So, right-click the script's icon in the systray, start 'Window Spy' and determine the window title you need by clicking the Excel window when you have the 'Credit Creator" open. The first row will give you the wintitle - copy and paste it to your script, replacing all instances of the old title. Perhaps, that is all you need to do... but before you change something, let's keep a backup of the original script (well, it is still in your post above, but anyway)
Chris_GVA
Posts: 4
Joined: 20 Mar 2018, 10:31

Re: Excel upgrade 2010 to 2016

26 Mar 2018, 08:01

Hello gregster,
Thank you for your help. I thought this was just the file name to change.
So I opened windows SPY and I see on the first field "Window Tile, Class and Process":
Credit Creator - Excel
ahk_class XLMAIN
ahk_exe EXCEL.EXE

I have replaced all the Microsoft Excel - Credit Creator by Credit Creator - Excel, but the script still running running without doing anything.
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: Excel upgrade 2010 to 2016

26 Mar 2018, 08:40

I looked at your code, and saw this:

IfWinNotActive, Microsoft Excel - Credit Creator, , WinActivate, Microsoft Excel - Credit Creator,

Do you have this on one line ?

If so, please change it to:

Code: Select all

IfWinNotActive, Credit Creator - Excel
WinActivate, Credit Creator - Excel
Does this pop up your excel file now ?
gregster
Posts: 8989
Joined: 30 Sep 2013, 06:48

Re: Excel upgrade 2010 to 2016

26 Mar 2018, 08:56

Actually, that should be ok, WalkerOfTheDay - not ideal, but ok.
https://autohotkey.com/docs/commands/WinActive.htm :
ExcludeTitle
Windows whose titles include this value will not be considered.

Note: Due to backward compatibility, IfWin[Not]Active interpret this parameter as a command if it exactly matches the name of a command. To work around this, use the WinActive function instead.
The problem is that probably something more changed in Excel 2016 compared to 2010, but without exactly knowing what the script should do and without having Excel 2016 (and assuming that it did work in Excel 2010), it won't be easy to isolate the problem - I don't see anything obvious, but I don't have Excel 2016, either. The original poster probably has to take a closer look at the code (and AHK in general) and try to debug it line by line.

If the script isn't really doing anything, it might be worth a try to run the script as admin, though (of course, with the new window title)
Last edited by gregster on 26 Mar 2018, 09:01, edited 1 time in total.
Chris_GVA
Posts: 4
Joined: 20 Mar 2018, 10:31

Re: Excel upgrade 2010 to 2016

26 Mar 2018, 09:01

Thanks walker. Tried it, but it is still not working.
In fact I use to have my excel file open and it should go directly in it automatically.

So, tried this one:

SetKeyDelay, 80
WinWait, Credit Creator - Excel,
IfWinNotActive, Credit Creator - Excel,
WinActivate, Credit Creator - Excel,
WinWaitActive, Credit Creator - Excel,
Sleep, 500
Send, {CTRLDOWN}f{CTRLUP}
Sleep, 500
Send, Order{ENTER}
Sleep,500
Send, {ESC}
Sleep, 500
Send, {DOWN}
Sleep, 300

Loop


and also this:

SetKeyDelay, 80
WinWait, Credit Creator - Excel,
IfWinNotActive, Credit Creator - Excel, , WinActivate, Credit Creator - Excel,
WinWaitActive, Credit Creator - Excel,
Sleep, 500
Send, {CTRLDOWN}f{CTRLUP}
Sleep, 500
Send, Order{ENTER}
Sleep,500
Send, {ESC}
Sleep, 500
Send, {DOWN}
Sleep, 300

Loop

nothing is working unfortunately.
gregster
Posts: 8989
Joined: 30 Sep 2013, 06:48

Re: Excel upgrade 2010 to 2016

26 Mar 2018, 09:02

try to run the script as admin

Is the script snippet

Code: Select all

Sleep, 500
Send, {CTRLDOWN}f{CTRLUP}
Sleep, 500
Send, Order{ENTER}
Sleep,500
Send, {ESC}
Sleep, 500
Send, {DOWN}
Sleep, 300
doing anything when you have Excel open?
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: Excel upgrade 2010 to 2016

26 Mar 2018, 09:20

Well, this part you posted works in my version of excel 2016.

Code: Select all

SetKeyDelay, 80
WinWait, Credit Creator - Excel,
IfWinNotActive, Credit Creator - Excel,
WinActivate, Credit Creator - Excel,
WinWaitActive, Credit Creator - Excel,
Sleep, 500
Send, {CTRLDOWN}f{CTRLUP}
Sleep, 500
Send, Order{ENTER}
Sleep,500
Send, {ESC}
Sleep, 500
Send, {DOWN}
Sleep, 300
What do you see when you double-click the script symbol in your taskbar ?
Chris_GVA
Posts: 4
Joined: 20 Mar 2018, 10:31

Re: Excel upgrade 2010 to 2016

26 Mar 2018, 09:35

It works!
Do not know how, but I've removed some of the green button application from the old file, add a new one, and it works. Still have some little issues on the "clipboard copy/paste" but this should not be a problem to resolve.

THANK YOU SO MUCH for your help and support guys.

Have a great day/evening :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: haomingchen1998 and 247 guests