Click here to Skip to main content
15,915,759 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to interface with an excel sheet that uses sendmessage. A user clicks on specific data in the excel sheet, which calls a VBA function that sends data to another application using sendmessage. I can't modify the excel sheet. I need to create a replacement application, that receives the message from excel, and parses that message.
Posted

You present very little information. Some useful tidbits would be:
1. The ID of the message.
2. Any parameters and the data types.
Simple like int and double or a complex structure.
3. Is the VBA using SendMessage or PostMessage
4. Is the VBA macro sending the message to a specific handle?
Or is it a broadcast message?

These things you need to know in order to do the c# implementation.
Basically you create a Windows Form application and then override the method PreProcessMessage

C#
public override bool PreProcessMessage(ref Message msg)
{
    if (msg.Msg == YOUR_MESSAGE_ID_AS_AN_INT)
    {
        // How to interpret the parameters depends on the VBA
        IntPtr wparam = msg.WParam;
        IntPtr lparam = msg.LParam;

        // If SendMessage was used a response is required.
        msg.Result = new IntPtr();

    }
    return base.PreProcessMessage(ref msg);
}
 
Share this answer
 
Not sure i understand you correctly, but if Excel macro sends message to another application with SendMessage[^] API function, the only way to catch it, is to use InSendMessage[^] function.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900