INF: Initiating DDE Conversation w/ Instance of Windows Excel

ID Number: Q29547

2.03 2.10 3.00

WINDOWS

docerr

Summary:

The documentation for the EXEC() macro on page 70 of the "Microsoft

Excel Function Reference" manual for version 3.0 incorrectly refers to

its return value as "the Microsoft Windows task ID number of the

started program." However, it is not the value returned by the Windows

KERNEL routine GetCurrentTask(). EXEC() returns the instance handle to

the EXEC()'d application.

More Information:

Windows and Excel do not provide an easy way to find out which

instance of Excel called the application. However, the correct value

can be obtained.

The following is a sample macro that uses the REGISTER and CALL

functions to obtain the instance handle to the version of Excel that

is running. That information then can be passed to the application

inside the EXEC call. However, the value in hInstance must be appended

as a string for the EXEC call.

The following is the text version of the macro sheet:

-------------------------------------------------------------

A | B

This is an example of how to obtain the |

instance and then pass that value to the|

EXEC'd application: |

|

=STEP() |

Get instance handle of current window. |

=REGISTER("USER","GetFocus","H")" |

=CALL(A7) | <== hWnd

-6 | <==GWW_HINSTANCE

=REGISTER("user","GetWindowWord","HHI")"| <==GetInstance

=CALL(GetInstance,hWnd,GWW_HINSTANCE)" | <== hInstance

=RETURN() |

Exec("YourApp.exe hInstance",1)" |

-------------------------------------------------------------

Note: For Microsoft Excel versions 2.x, the corresponding

documentation for the EXEC() macro is on page 275 of the "Microsoft

Excel Functions and Macros" manual.