# Dde\_execute an excel macro from prolog. How do I pass parameters to the macro?

**URL:** https://swi-prolog.discourse.group/t/dde-execute-an-excel-macro-from-prolog-how-do-i-pass-parameters-to-the-macro/853
**Category:** Help!
**Created:** [June 23, 2019, 6:08pm UTC](https://swi-prolog.discourse.group/t/dde-execute-an-excel-macro-from-prolog-how-do-i-pass-parameters-to-the-macro/853 "2019-06-23T18:08:07Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![John2003tw](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@John2003tw](https://swi-prolog.discourse.group/u/John2003tw)
#### Post date: [June 23, 2019, 6:08pm UTC](https://swi-prolog.discourse.group/t/dde-execute-an-excel-macro-from-prolog-how-do-i-pass-parameters-to-the-macro/853/1 "2019-06-23T18:08:07Z")

</div>

Hi experts,

Could someone help to solve my question? Here I want to execute an Excel VBA macro, called execute\_demo from Swi prolog DDE.  
Without parameters, it runs well and return True.  
But, I need to pass parameters into the macro. I tried many possible combination but fail, such as dde\_execute(C,’[run(“execute\_demo 1”)]’).

I don’t have any clues to do it. Can anyone help to shed light on it?

Thank you for your helps in advance.

Excel vba:

```prolog
Public sub execute_demo( i as integer)
  msgbox(i)
end sub

```

SWI prolog:

```prolog
run_excel_macro() :-
      open_dde_conversation('Excel','[swipl_excel.xlsm]S',C),
       dde_execute(C,'[run("execute_demo")]'),
       close_dde_conversation(C).

```

---

<div class="post-metadata">

### Author: ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)
#### Post date: [June 24, 2019, 6:57am UTC](https://swi-prolog.discourse.group/t/dde-execute-an-excel-macro-from-prolog-how-do-i-pass-parameters-to-the-macro/853/2 "2019-06-24T06:57:59Z")

</div>

A quick check tells me that dde\_execute/3 simply passes the command as a string to Windows DDE API. Thus, this seems more a question about using Excel through DDE than a Prolog question.

---

<div class="post-metadata">

### Author: ![John2003tw](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@John2003tw](https://swi-prolog.discourse.group/u/John2003tw)
#### Post date: [June 26, 2019, 4:45pm UTC](https://swi-prolog.discourse.group/t/dde-execute-an-excel-macro-from-prolog-how-do-i-pass-parameters-to-the-macro/853/3 "2019-06-26T16:45:01Z")

</div>

Dear Jan,  
Thank you for the replying. Checking SWI prolog manul, there is dde\_execute/2, not dde\_execute/3. Is it undocumented for dde\_execute/3?

Thanks,  
John Lin

---

<div class="post-metadata">

### Author: ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)
#### Post date: [June 27, 2019, 8:21am UTC](https://swi-prolog.discourse.group/t/dde-execute-an-excel-macro-from-prolog-how-do-i-pass-parameters-to-the-macro/853/4 "2019-06-27T08:21:42Z")

</div>

My mistake. It is /2.
