Jump to content
Macro Express Forums

Windows API call from Excel 2007 is "sticky" causing inconsistent behavior


Recommended Posts

Environment: Windows XP/Excel 2007/ MacroExpress 3.7d build 1




Will try my best to explain the problem with a scenario...


In Excel 2007, I have two Command Buttons, BtnA and BtnB. Each has been programmed using Excel VBA to call separate macros in Macro Express 3.x, say BtnA calls MacroA and BtnB calls MacroB.


When I press BtnA, it calls MacroA - correct behavior

Then I press BtnB, it calls MacroB - correct behavior

Let us say, I now press BtnA. It should call MacroA, but instead it calls the last played macro, MacroB - inconsistent behavior

I again press BtnA, this time it calls the correct macro, MacroA - correct behavior


It seems as if there is a time lag somewhere in the API call threads, that there is a persistence of previously called macro that leads to above inconsistent behavior. Sometimes it behaves fine, other times, "sticky" behavior as above is exhibited.


Would really appreciate any pointers to resolve as it is key for my project that this API calls work!


Regards, and thanks in advance!


Link to comment
Share on other sites

While it would seem likely that the problem is in the interface between the programs, have you tried duplicating the button actions not using Excel ie manually starting in ME3, timed similar to the problem to eliminate the possibility it is occurring in the two macros? I can't think of any scenarios in ME3 that would fit, but in all these problems, you start with the simple stuff first and eliminate.

Link to comment
Share on other sites

Are you sure that you are sending the name of the macro followed by a NUL (ASCII 0)? The NUL is supposed to clear the buffer containing the name of the macro. The example from the help looks like this:

 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

Note that the final PostMessage sends the NUL.

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.

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.

  • Create New...