In the past I've used dde to link to excel and poke/request data, but so far I've only done it in aspect (procomm scripting lang). I'm curious how it's done in real life using the dde api functions.

So far this is what I'm (pretty) sure of:

;this is successful
2) DdeCreateStringHandle w/ service name
3) DdeCreateStringHandle w/ topic name
4) DdeConnect w/ hTopic and hService
;this successfully establishes a connection

I've got to open excel first for this to work since I haven't programmatically done this. But there are at least two things that I don't know how to do: pass the fileopen command -- , pass the row/col info "r1c1" for example.

Is the FileOpen command sent in a DdeClientTransaction call w/ XTYP_EXECUTE? Then, is the row/col info sent in the form of another DdeClientTransaction call, and if so how?

All that I've been able to find in my googling is mostly non-english results. The english results are either vc++/mfc, vb, matlab, etc specific. Does anyone have any straightforward language-inspecific docs on this or know where I can find any? Or if someone could show me a general outline (i.e. like steps 1-4 above) that would be fantastic.

Posted on 2002-09-20 10:40:25 by Will
Hi Will,

Have a look at savage's mircdde program. It's an easy
to understand sample of a simple DDE client. It should
answer your questions.

You can find it here:
Posted on 2002-09-22 10:33:53 by Wayne
Thanks Wayne. I've seen Savage's example and the client/server example on Iczelion's site. There's more info that needs to be passed to excel though (i.e. file name, possibly the worksheet name, and the row/col info). My question is excel-specific I guess--how do you pass that other info to excel? Sorry if I wasn't clear on that. Do I just need multiple DdeClientTransaction calls to pass the other info?
Posted on 2002-09-22 11:08:19 by Will

For excel:

Establish connection with topic "System"
You can issue commands to excel with this connection.
If I remember correctly, you have to enclose commands in brackets i.e. "" opens new workbook. In your case something like "" Not 100% sure on syntax here. I will try to find more info.

Also, with "system" topic you can request a list of all topics supported. To do this use "Topics" as Item.
In excel, any loaded workbooks are listed as topics.

To 'poke' a cell with data, create another connection with
your workbook as the "Topic". You can then 'poke' using
"R1C1" format.

This is basicly steps needed. Like I said, I'm not 100% on the syntax.
Posted on 2002-09-22 18:54:52 by Wayne
Good deal. The syntax is I'm pretty sure. Thanks a bunch. I'll fiddle around a bit and see if I can get it working with your tips. Please don't feel like you have to search for any more info for me. I mean you can if you want to ;) but I just wanted a basic outline of the necessary steps.

Thanks a bunch,
Posted on 2002-09-23 14:13:55 by Will
Got single commands to work i.e (,...) but
no success with command yet. Getting Transaction Failed Error. Could be the syntax.

I'll keep trying (I'm interested also).
Please Post if you have any results.

Documentation on Excel DDE commands is almost non-existant
after Excel 5. Of course that's because COM took over.

Posted on 2002-09-23 18:40:22 by Wayne
You'll have to forgive me. For the past few days I've been working such long hours that I've barely had enough time outside of work to sleep. I did get the "" to work though (iirc....pretty sure anyways). I'm home from work early (1/4 till 9) and taking a break from everything. Tomorrow i'll spend some more time with this and post an update of my luck (or lack thereof). :) Thanks for your interest Wayne. When we're done we'll be able to post examples so other people will have an easier time with the learning curve of dde (even though it seems like MS is phasing it out).

Posted on 2002-09-24 21:42:23 by Will
I finally managed to get command to work the other
night. Seems like it does'nt like spaces. da!
Anyway, I modified savage's IRCDDE code to test on Excel.
Right now, all it does is open a wookbook and poke a value in cell A1.

Posted on 2002-09-25 09:28:21 by Wayne
Cool. Your example works on excel2k which is what I've got at home. The code that I was working on is at work and I forgot to email it to myself. I'll play with it a little tonight and see what I can come up with. Good deal.

Posted on 2002-09-25 20:55:54 by Will
Well, I found source (vb3 I think) on MS's site for an app that uses DdeConnectList to enum all running dde servers that respond to a dde connection request with a topic of "system". It found 5 servers, and my little test app went through the loop 5 times but all 5 were empty strings and eax returned 1 for the length. Weird stuff.

The only thing that I managed to successfully do is re-arrange your example code in a loop and poke 1 through 1000 to rxc1. It goes pretty fast too, faster then I thought it would anyways.

Anyways, that's where I am right now.

Posted on 2002-09-30 13:08:03 by Will
Hi Will,
Sounds like your making some progress. I, on the other hand
have not done any more as I've started a semi-major house
project. It will keep me tied up until next week. I'll get
back to it then. (Or if it rains)

If you have the Platform SDK there are some 'C' DDE examples
to look over.

Just curious, are you doing this to learn DDE or do you have
a need to control Excel ?
I only ask because there are other mechanisms you may want to look into also.

Posted on 2002-09-30 21:24:13 by Wayne
Well I wanted to explore other options then using dde macros in aspect or vba. Periodically I've got to throw some data in an .xls file and send it off to some other departments at work. If it can be done using masm I'd be a happy camper. :) Other than excel I can't imagine what I'd use it for though.
Posted on 2002-10-01 10:14:32 by Will
Beside DDE you could also consider using COM or ODBC.
IMO, using COM sounds like overkill for what you want to do.
ODBC might an option. I had an example that I had posted on the old messageboard but I can't find it right now. I'll look for it. There are some limitions.

I am not trying to talk you out of using DDE, just thought I would suggest other things. Your needs of your application should be the basis for the method you choose.

Posted on 2002-10-02 06:36:09 by Wayne