Hi David,
An alternative would be to use a macro to launch the macro that you wish to execute, that way you can enumerate the environment variable in the initial macro to build the path to the macro which you wish to execute..
So say you have a RunThisOne macro in your Application folder (i.e. C:\\Program Files (x86)\\Attachmate\\EXTRA!\\), then when you map your control to run that macro add a space and then the name of the macro in your myDir folder that you wish to execute.
your RunThisMacro might look like this:
Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type
Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Declare Function OpenProcess Lib "kernel32" Alias "OpenProcess" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, lpProcessAttributes As Any, lpThreadAttributes As Any, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
Const SYNCHRONIZE = 1048576
Const NORMAL_PRIORITY_CLASS = &H20&
Dim pInfo As PROCESS_INFORMATION
Dim sInfo As STARTUPINFO
Sub Main
Dim EBrunPath as String, MacroPath as String
'*** Set the Path to Ebrun.exe
EBrunPath = "C:\\Program Files (x86)\\Attachmate\\EXTRA!\\"
Dim RunThisOne As String
Dim sNull As String
Dim lSuccess As Long
Dim lRetValue As Long
'*** Get parameter passed on the command line (in this instance, the name of the macro you wish to execute
RunThisOne = Command$
'*** Set that path to the centrally managed macros
MacroPath = Environ$("USERPROFILE") + "\\Documents\\Attachmate\\EXTRA!\\MACROS\\MyDir\\"
'*** Execute the command to launch the relevant macro and wait for it to terminate before exiting
sInfo.cb = Len(sInfo)
lSuccess = CreateProcess(sNull, EBRunPath + "Ebrun.exe "+ MacroPath + RunThisOne, ByVal 0&, ByVal 0&, 1&, NORMAL_PRIORITY_CLASS, ByVal 0&, EBrunPath, sInfo, pInfo)
Do While lSuccess > 0
nn = GetExitCodeProcess(pInfo.hProcess, nExitCode)
If nExitCode = 0 Then lSuccess = 0
RunAndReturn = 0
loop
RunAndReturn = 1
End Sub
This way you can completely isolate your myDir macros and users can't inadvertently screw things up by accidentally changing their default macro path.
This may not work for you if you have roaming users, which is likely why you have not just dropped your macros in a common location in the first instance.