calling Excel sub/function via DDE - "Argument not optional"

rolex

New Member
Joined
Nov 14, 2002
Messages
11
I'm trying to call an Excel sub or function from another application via DDE. So far I had succeeded calling any sub that has no parameters, via Run method, like this:

ch = DDEInitiate("excel", "system")
DDEExecute ch, "[Run(""test.xls!Test"")]"

Now I'm trying to call a sub with parameters:

DDEExecute ch, "[Run(""test.xls!Test"",123)]"

where Test is a sub with one Integer parameter.

When called, this results in Excel error: "Argument not optional". Any ideas what could be wrong there?
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
On 2002-11-26 04:14, Andrew Poulsom wrote:
Just guessing, but try:

DDEExecute ch, "[Run(""test.xls!Test(123)"")]"

nah, tried that already...
Macro "test.xls!Test(123)" cannot be found
 
Upvote 0
Is it as simple as adding a space before the comma?

DDEExecute ch, "[Run(""test.xls!Test"" ,123)]"

Or could you use the Call keyword like this:

DDEExecute ch, "[Call test.xls!Test(123)]"
 
Upvote 0
Alas, that doesn't work (and looks like it shouldn't), according to documentation on Run method, syntax is Run(macro_name,arg1,arg2...)
 
Upvote 0
In the Run Method example in Help there is:

mySum = Application.Run("MYCUSTOM.XLM!My_Func_Sum", 1, 5)

Notice the spaces after (not before, my mistake) the commas. So maybe:

DDEExecute ch, "[Run(""test.xls!Test"", 123)]"

Also note that normally arguments for methods are enclosed in brackets only if the result of the method is assigned to a variable. So:

Result = Application.Run("MyMacro")

but

Application.Run "MyMacro"

Maybe try:

DDEExecute ch, "[Run ""test.xls!Test"", 123]"

Sorry this is taking so long.
 
Upvote 0
Tried all possible variations, no dice..
I've noted that calling standard methods like New, select etc., arguments accepted without any problem, so this might not be the problem of syntax at all.

I wish someone who had called user functions successfully via DDE could help..

Thanks anyway
 
Upvote 0
I know I am resurrecting a 2002 post, but now in 2024, I am facing the same situation.

Did anyone ever figured out how to do it ?
So far, the only way I was able to work "around" it, is to write the value in a cell and use that cell in my function instead of a parameter. (if the argument are option, you could do "if missing" then read that cell, but difficult if you want to run the function without any arguments at all).

Hopefully someone know the way to do it....

I shouldn't be using DDE and XML 4.0 (excel macro) anymore but that's the only possibility with what I am facing.
 
Upvote 0

Forum statistics

Threads
1,223,605
Messages
6,173,321
Members
452,510
Latest member
RCan29

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top