Jump to content
Macro Express Forums

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 weeks later...

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 ?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

 

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

  • 3 weeks later...

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%"/>
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 6 months later...

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???

Link to comment
Share on other sites

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...