gagangoomer Posted June 16, 2014 Report Share Posted June 16, 2014 Is there any way by which i can call the ME macro in a VBA macro ? Vice Versa is possible but i'm not sure about this. Also how can we debug the External script in ME. As i've seen a small mistake in the code can sometime can take a lot of time debugging it. Quote Link to comment Share on other sites More sharing options...
rberq Posted June 16, 2014 Report Share Posted June 16, 2014 Look up Command Line Parameters in the Macro Express Help screens. You can call either macexp.exe or meproc.exe and specify a macro to be run. I have done it from VB programs but I'm not really familiar with VB scripting so I can't give you an example. Quote Link to comment Share on other sites More sharing options...
joe Posted June 16, 2014 Report Share Posted June 16, 2014 gag- When using the External Script command for VBScript it returns errors to the variable set to recieve results from the script. When developing these programs I always use 'Option Explicit' as well as NOT using 'On Error Resume Next' so when the millions of times my development throws errors, I can see the error line number and the error in the receiving variable by placing MXPro Pause or MessageBox, after the External Script line to display the receiving variable, or by just popping open the debug variables window. Hope this helps. Quote Link to comment Share on other sites More sharing options...
gagangoomer Posted June 18, 2014 Author Report Share Posted June 18, 2014 Thanks everyone...i got the idea Quote Link to comment Share on other sites More sharing options...
gagangoomer Posted June 19, 2014 Author Report Share Posted June 19, 2014 I just checked through the command line parameters in MEP. Is there any way through which we can stop an existing Macro before running another macro ? Quote Link to comment Share on other sites More sharing options...
joe Posted June 19, 2014 Report Share Posted June 19, 2014 One of the things needed for unattended operations is to set up an on/off switch in the macro so it knows itself when it should start and stop.An on/off switch can be something as simple as a file in a folder. If it exists, then the macro runs, otherwise it stops. Do this by creating the switch, which would be a separate macro to simply turn the switch on (create a file) or turn it off (delete the file). Set the macro that you want to run unattended to fire every few seconds (or whatever interval trips your trigger). First thing it needs to do is check for the existence of the file. If it isn't there, the switch is off, and it stops itself. If the file is there then it moves past the checkpoint, and runs.How do you stop it?Well, most of the macros created for my operations all run in some repeat loop and at the top of the loop they check the on/off switch. If it is off (file not there) then the macro stops itself.It is a very simple and basic way to have macros not only run and stop unattended, but to also change their course when they get past the checkpoint. How? Instead of having the macro just check the on/off switch, place instructions in the file for the course the macro should take next time it fires.An on/off switch like this gives us the ability to externally stop a macro as well as to have a nice conversation with it.Hope this helps. Quote Link to comment Share on other sites More sharing options...
gagangoomer Posted July 2, 2014 Author Report Share Posted July 2, 2014 Suppose, i'v some case id's in a spreadsheet which needs to follow certain steps using IE. So for every step if the ME macro needs to check if there is a file in a folder then run the macro else stop it. Don't you think it is going impact the speed of the macro ? Quote Link to comment Share on other sites More sharing options...
Cory Posted July 2, 2014 Report Share Posted July 2, 2014 I'm jumping in here without reading the entire thread so excuse me if I'm out of line. It sounds like you need a means of detecting if a macro is running from another macro. For something like this I would use the registry. Since it's loaded into memory access to it is very fast. Quote Link to comment Share on other sites More sharing options...
joe Posted July 3, 2014 Report Share Posted July 3, 2014 Don't you think it is going impact the speed of the macro ? I am absolutely positive it would impact the macro speed, but by how much? It takes about .03 ms to check if a file exists, which means that for 100,000 checks it would add 3+ seconds onto the macro's runtime. That can't be bad. The code below took 30.22 seconds to check for the existence of a file 1,000,000 (1 million) times. External Script: VBScript // Timer start Repeat Start (Repeat 1000000 times) If File Exists: "c:\temp\filename.txt" MessageBox: %macroName% End If End Repeat External Script: VBScript // Timer stop Quote Link to comment Share on other sites More sharing options...
paul Posted July 8, 2014 Report Share Posted July 8, 2014 Is there any way by which i can call the ME macro in a VBA macro ? Look up Command Line Parameters in the Macro Express Help screens. You can call either macexp.exe or meproc.exe and specify a macro to be run. There's a better way, which I will describe next time if you are interested. Quote Link to comment Share on other sites More sharing options...
joe Posted July 9, 2014 Report Share Posted July 9, 2014 Another question along this same line that would be great to have resolved is how can VBScript call a macro using PostMessage? I know that PostMessage "System Activation" is built in to MXPro, and I've read their Delphi sample, but how could it be done through VBScript? Quote Link to comment Share on other sites More sharing options...
paul Posted July 29, 2014 Report Share Posted July 29, 2014 Another question along this same line that would be great to have resolved is how can VBScript call a macro using PostMessage? I know that PostMessage "System Activation" is built in to MXPro, and I've read their Delphi sample, but how could it be done through VBScript? Here's an example using AutoIt, for which you need to have an existing macro called TestMacro. I don't know whether it's possible to pass parameters to the target macro - I suspect not. Variable Set String %tMacroName% to "TestMacro" External Script: AutoIt <VARIABLE SET STRING Option="\x00" Destination="%tMacroName%" Value="TestMacro" NoEmbeddedVars="FALSE"/> <EXTERNAL SCRIPT Language="AutoIt" Dest="%t[1]%" Script="$dll = DllOpen(\"user32.dll\")\r\n$hwnd = DllCall($dll, \"hwnd\", \"FindWindowW\", \"wstr\", \"TMainWin\", \"wstr\", \"Macro Express Player\")\r\n$hwnd = $hwnd[0]\r\nFor $i = 1 to StringLen($CmdLine[1])\r\n $Result = DllCall($dll, \"bool\", \"PostMessage\", \"HWnd\", $hwnd, \"uint\", 1044, _\r\n \"wparam\", Asc(StringMid($CmdLine[1], $i, 1)), \"lparam\", 0)\r\nNext\r\n$Result = DllCall($dll, \"bool\", \"PostMessage\", \"HWnd\", $hwnd, \"uint\", 1044, \"wparam\", 0, \"lparam\", 0)\r\nDllClose($dll)\r\n\r\n" Parameters="%tMacroName%"/> Quote Link to comment Share on other sites More sharing options...
joe Posted July 30, 2014 Report Share Posted July 30, 2014 Paul - That looks very nice ... but what are the properties to be set in the "TestMacro" activation tab? Quote Link to comment Share on other sites More sharing options...
paul Posted July 30, 2014 Report Share Posted July 30, 2014 Paul - That looks very nice ... but what are the properties to be set in the "TestMacro" activation tab? Well, in my example, I've not set any. What properties are you referring to? Quote Link to comment Share on other sites More sharing options...
joe Posted August 5, 2014 Report Share Posted August 5, 2014 Paul - I was referring to the macro System Event macro activation feature. When it gets down to the Windows messaging system, I am totally ignorant and blind. My eyes cross whenever I attempt to think about it. That being said, I think it would be nice to know how to set the System Event macro activation fields along with how to write a simple AutoIt, or preferably, VBScript program to handle firing a macro via PostMessage. I would imagine VBScript would need to use some WMI calls. Another eye-crossing thing for me to even begin thinking about. Quote Link to comment Share on other sites More sharing options...
Cartwheels Posted February 11, 2015 Report Share Posted February 11, 2015 Is there any way by which i can call the ME macro in a VBA macro ? Maybe I'm missing what you are looking for but... Shell ("C:\Macro Express3\MeProc.exe /Ayour_macro_name_here") In other words Shell ("C:\Macro Express3\MeProc.exe /A Then put your MEP macro name in after the A You would have to change the path to MacroExpressPro and point to wherever you have your macros stored. I use this in ME3 and would assume that it works with MEP??? Quote Link to comment Share on other sites More sharing options...
Samrae Posted February 13, 2015 Report Share Posted February 13, 2015 From the Macro Express Pro help topic "Macro Activation": VBA Example HWND hwnd = FindWindow("TMainWin", "Macro Express Player"); if( IsWindow(hwnd) ) { for(int x = 0; x < strlen(s); x ++) PostMessage(hwnd, WM_USER+20, s[i], 0); PostMessage(hwnd, WM_USER+20, 0, 0); } else MessageBox(GetForegroundWindow(), "Macro Express is not running", "Error", 0); Private Declare Function FindWindow _ Lib "User32" Alias "FindWindowA" ( _ ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long Private Declare Function PostMessage _ Lib "User32" Alias "Porterage" ( _ ByVal Wand As Long, _ ByVal MSG As Long, _ ByVal warm As Long, _ ByVal Parma As Long) As Long Private Sub Unsacred) 'Runs a macro express macro Const WM_USER = &H400 Const Command = WM_USER+20 Const Macroname = "Macroname" Dim hwnd, I, Result As Long hwnd = FindWindow("TMainWin", "Macro Express Player") For I = 1 To Len(Macroname) Result = PostMessage(hwnd, Command, Asc(Mid(Macroname, I, 1)), 0) Next I Result = PostMessage(hwnd, Command, 0, 0) End Sub Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.