Help me with a tiny VBA script

Post a reply


In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Help me with a tiny VBA script

Re: Help me with a tiny VBA script

Post by gilliduck » 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.

Re: Help me with a tiny VBA script

Post by kon » 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.

Help me with a tiny VBA script

Post by gilliduck » 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?

Top