Call AHK function from VBA(MS ACCESS) using Autohotkey.dll

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jony26
Posts: 10
Joined: 10 Feb 2017, 04:33

Call AHK function from VBA(MS ACCESS) using Autohotkey.dll

29 Dec 2018, 02:19

I try to call function from VBA(MS ACCESS) using Autohotkey.dll

Code: Select all

Dim AhkCom As AutoHotkey.CoCOMServer
Set AhkCom = New AutoHotkey.CoCOMServer
AhkCom.ahktextdll
AhkCom.ahkFunction "msgbox", "hello"
but nothing happens,msgbox window does not appear,
what am I doing wrong?
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Call AHK function from VBA(MS ACCESS) using Autohotkey.dll

30 Dec 2018, 20:24

Code: Select all

Dim AhkCom As AutoHotkey.CoCOMServer
Set AhkCom = New AutoHotkey.CoCOMServer
AhkCom.ahktextdll
AhkCom.ahkExec "msgbox", "hello"
jony26
Posts: 10
Joined: 10 Feb 2017, 04:33

Re: Call AHK function from VBA(MS ACCESS) using Autohotkey.dll

11 Jan 2019, 03:49

HotKeyIt, as I understood from your links, function libraries should be placed along paths:

Code: Select all

%A_ScriptDir%\Lib\  ; Local library - requires AHK_L 42+.
%A_MyDocuments%\AutoHotkey\Lib\  ; User library.
path-to-the-currently-running-AutoHotkey.exe\Lib\  ; Standard library.
I did so and the example from the documentation works fine:

Code: Select all

dllpath:=A_AhkDir "\AutoHotkey.dll"
DllCall("LoadLibrary","Str",dllpath) ; Load the AutoHotkey module.
DllCall(dllpath "\ahktextdll","Str","#Persistent`nMyFunc(param){`nSleep 10000`nMsgBox `% param`n}","Str","","CDecl") ; start a new thread, just the function.
Msgbox % DllCall(dllpath "\ahkFunction","Str","MyFunc","Str","Hello World!","CDecl Str") ; call the function.
when I run it from AHK, but when I call the same function from VBA:

Code: Select all

Dim AhkCom As AutoHotkey.CoCOMServer
Set AhkCom = New AutoHotkey.CoCOMServer
AhkCom.ahktextdll
AhkCom.ahkFunction("MsgBox", "hello")
it doesn’t work, maybe because in the case of VBA the path

Code: Select all

%A_ScriptDir%\Lib\
does not make sense?
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Call AHK function from VBA(MS ACCESS) using Autohotkey.dll

11 Jan 2019, 09:28

It is not because it does not make sense but because the dll is loaded via MemoryModule and takes over the path of executable "path-to-the-currently-running-AutoHotkey.exe" -> "C:\Program Files\Microsoft Office\..."

Therefore you can place a link in directory where MS ACCESS executable is a link to your lib folder (name it lib [lib.lnk]).
jony26
Posts: 10
Joined: 10 Feb 2017, 04:33

Re: Call AHK function from VBA(MS ACCESS) using Autohotkey.dll

14 Jan 2019, 08:14

HotKeyIt, I put all "*.ahk" files from "ahkdll-v1-release-master\Compiler\Lib\" folder into the "c:\Program Files (x86)\Microsoft Office\Office16\Lib\" folder, but my script still don't work. I must say that I did not find the definition of the "ahkFunction" in that "*.ahk" files.

Am I understand correctly that among that "*.ahk" files there should be an "ankFunsion.ahk" file? since it's not there ...

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 320 guests