Page 1 of 1

Please help how to use Autohotkey Functions in VBA

Posted: 24 Jul 2018, 01:06
by ocnuybear
Hi All,

I'm new to Autohotkey and want to use it to send keys to an inactive window.

The script below does exactly what I need.

Code: Select all

settitlematchmode,2
controlsend,,{Escape down}{Escape up}, VLC
But can I call these functions from Excel VBA using COM connection to Autohotkey?

If so what I have tried is to first register the 32 bit autohotkey.dll which registered correctly.

But as soon as I try using the VBA code:

Code: Select all

Sub atest()
Dim AHK As Object
Set AHK = CreateObject("AutoHotkey.Script")
AHK.ahktextdll ("MsgBox Hello World!" & Chr(13) & "ExitApp")
End Sub
VBA complains about activex controls.

Can anyone help me please?

Re: Please help how to use Autohotkey Functions in VBA

Posted: 25 Jul 2018, 15:23
by HotKeyIt
You have to add a reference to autohotkey.dll in vba, are you using office? See https://msdn.microsoft.com/en-us/vba/la ... -reference

Re: Please help how to use Autohotkey Functions in VBA

Posted: 27 Jul 2018, 13:15
by ocnuybear
I have added the 32 bit autohotkey.dll to the VBA reference, but it is still not working

Re: Please help how to use Autohotkey Functions in VBA

Posted: 28 Jul 2018, 04:25
by HotKeyIt
Which dll have you used v1 or v2?

Re: Please help how to use Autohotkey Functions in VBA

Posted: 28 Jul 2018, 13:44
by ocnuybear
I downloaded this file: ahkdll-v1-release-master.zip and used the dll from Win32a dir

Re: Please help how to use Autohotkey Functions in VBA

Posted: 28 Jul 2018, 13:53
by ocnuybear
I just tried the one in v2 & it also gives the same error

Re: Please help how to use Autohotkey Functions in VBA

Posted: 28 Jul 2018, 15:35
by HotKeyIt
Try using win32w, I will test on monday at work as I don't have office at home.
Are you trying to do that in excel?

Re: Please help how to use Autohotkey Functions in VBA

Posted: 29 Jul 2018, 01:25
by ocnuybear
I want to use it in Excel, but the main reason is to understand loading the autohotkey DLL & how to call it's functions from other programs like VBA.

Is the autohotkey a native DLL using the stdcall calling convention?

The reason I ask is DLL's created in Dot Net are managed DLL's and some 3rd party software cannot use it.

I'm new to the DLL loading concept, but have intermediate experience in different programming languages - especially automation.

Update: 30 Jul 2018

Just tried the DLL from win32w, but same error - I used different win10 pc, registered the dll with regsvr32.exe d:\AutoHotkey.dll and also added it to VBA reference

Re: Please help how to use Autohotkey Functions in VBA

Posted: 03 Aug 2018, 08:40
by ocnuybear
Can anyone give feedback please?