Help me with a tiny VBA script

Discuss other programming languages besides AutoHotkey
gilliduck
Posts: 265
Joined: 06 Oct 2014, 15:01

Help me with a tiny VBA script

14 Mar 2016, 20:04

I'm trying to make a basic macro in Outlook that will launch an AHK script when I click it. Making the button is easy, the script is escaping me though.

Googling suggests I should do something like

Code: Select all

Sub RunScript()
    Set WshShell = WScript.CreateObject("WScript.Shell")
    WshShell.CurrentDirectory = "C:\folder\subfolder\"
    WshShell.Run "ahkScript.ahk"
End Sub
But that's not working (no errors when I try to just run it from Outlook, gives an Object missing error when I try to run it in Microsoft VBA).

Anyone got a minute and any skill with VBA to help me out?
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: Help me with a tiny VBA script

14 Mar 2016, 21:53

Code: Select all

Option Explicit

Sub RunScript()
    Dim WshShell As Object
    Set WshShell = CreateObject("WScript.Shell") ' Removed WScript prefix from CreateObject
    ' I think you need literal quotes around the path if it contains any spaces
    WshShell.Run """C:\folder\subfolder\ahkScript.ahk"""
End Sub
I tested this in Excel. It seems to work.
gilliduck
Posts: 265
Joined: 06 Oct 2014, 15:01

Re: Help me with a tiny VBA script

15 Mar 2016, 11:08

That does the trick Kon! Seeing a working version always helps me figure out where I went wrong too, thanks.

Return to “Other Programming Languages”

Who is online

Users browsing this forum: No registered users and 15 guests