Pass parameters to word 2003 from excel vba

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15619
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Pass parameters to word 2003 from excel vba

Post by ChrisGreaves »

http://support.microsoft.com/?kbid=274284
This is about the second time in my life when pasted code for a new technique has worked first off.
I've had a cuppa and a lie down and am recovered now.

Question 1: Where has this been all my (VBA) life? I've been using Dictionaries for about 5 years to chat between Word & Excel. This article includes the nostalgic text " ... you would typically use the ToolsMacro WordBasic command."

Question 2: Who else (of you) is using this DDE technique between Word & Excel?

Question 3: Known traps for young players?

Word 2003 VBA:

Code: Select all

Sub Test (iNum As Integer)
    MsgBox "The value is: " & iNum
End Sub
Sub Test2 (strFname As String, strLname As String, iNum As Integer)
    MsgBox "The values are: " & strFname & "," & strLname & "," & iNum
End Sub
Excel 2003 VBA:

Code: Select all

Sub DDEtoWord()
    Dim chanNum As Variant
    chanNum = DDEInitiate("WinWord", "System")
    DDEExecute chanNum, "[DDETesting.Test(5)]"
    DDEExecute chanNum, "[DDETesting.Test2(""John"",""Doe"", 12)]"
    DDETerminate chanNum
End Sub
Last edited by ChrisGreaves on 15 May 2011, 20:49, edited 1 time in total.
There's nothing heavier than an empty water bottle

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15619
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Pass parameters to word 2003 from excel vba

Post by ChrisGreaves »

ChrisGreaves wrote:Question 3: Known traps for young players?
If you get the module name wrong, everything stops with a RTE '438' Object doesn't support this property or method.

And what do I see in my Normal.dot?
A module "WordTmpDDEMod"
and within that module some code:-

Code: Select all

Private Sub TmpDDE()
WordBasic.Call "BestFit.Test", 5
End Sub
There's nothing heavier than an empty water bottle