DDE between Excel and Word

S

Sathya

How can I pass a value from Excel to Word which is stored in a
variable?
How can this be done using Macros?

I have a problem in the following code
For Example :-

Macro in Excel
-----------------
Sub DDEtoWordOld()
Dim chanNum As Variant
Dim test As String
test = "Value"
chanNum = DDEInitiate("WinWord", "System")
DDEExecute chanNum, "[DDETesting.Test(""Value"")]"
DDEExecute chanNum, "[DDETesting.Test(test)]"
DDETerminate chanNum
End Sub

Macro in Word -Module name -DDETesting
-----------------------------------------
Sub test(Test As String)
MsgBox "The value is: " & Test
End Sub

DDEExecute chanNum, "[DDETesting.Test(""Value"")]" -This line of code
works perfectly when a string is passed directly as a parameter.

DDEExecute chanNum, "[DDETesting.Test(' " & test & " ')]" -This line
gives a "Syntax error" during run time in a dynamically created macro
WordTmpDDEMod

Sub TmpDDE()
WordBasic.Call "DDETesting.Test",'value' ------SYNTAX ERROR in
this line
End Sub

Can anyone help me out in knowing How this variable should be
passed???
 
H

Howard Kaikow

I have not looked at DDE in a long time, but the preferred method would be
to not use DDE.
Create a Word object within the Excel macro and Automate Word from Excel.

Look up CreateObject and New in the ObjectBrowser.
 
S

Sathya

Can i add a menu item in excel thro word macros?
When the menu item is selected ..the activecell.value should be
available for word macro..
if i open an excel from word macro and try to capture activecell.value
...
Is this possible using word macro?


Howard said:
I have not looked at DDE in a long time, but the preferred method would be
to not use DDE.
Create a Word object within the Excel macro and Automate Word from Excel.

Look up CreateObject and New in the ObjectBrowser.

--
http://www.standards.com/; See Howard Kaikow's web site.
Sathya said:
How can I pass a value from Excel to Word which is stored in a
variable?
How can this be done using Macros?

I have a problem in the following code
For Example :-

Macro in Excel
-----------------
Sub DDEtoWordOld()
Dim chanNum As Variant
Dim test As String
test = "Value"
chanNum = DDEInitiate("WinWord", "System")
DDEExecute chanNum, "[DDETesting.Test(""Value"")]"
DDEExecute chanNum, "[DDETesting.Test(test)]"
DDETerminate chanNum
End Sub

Macro in Word -Module name -DDETesting
-----------------------------------------
Sub test(Test As String)
MsgBox "The value is: " & Test
End Sub

DDEExecute chanNum, "[DDETesting.Test(""Value"")]" -This line of code
works perfectly when a string is passed directly as a parameter.

DDEExecute chanNum, "[DDETesting.Test(' " & test & " ')]" -This line
gives a "Syntax error" during run time in a dynamically created macro
WordTmpDDEMod

Sub TmpDDE()
WordBasic.Call "DDETesting.Test",'value' ------SYNTAX ERROR in
this line
End Sub

Can anyone help me out in knowing How this variable should be
passed???
 
N

Norman Goetz

On 16 Mar 2005 03:19:05 -0800, Sathya wrote:
Change the following part of your code
-----------------
Sub DDEtoWordOld()
Dim chanNum As Variant
Dim test As String
test = "Value"
chanNum = DDEInitiate("WinWord", "System")
DDEExecute chanNum, "[DDETesting.Test(""Value"")]"
' DDEExecute chanNum, "[DDETesting.Test(test)]"
DDEExecute chanNum, "[DDETesting.Test(" & Chr$(34) & test &
Chr$(34) & ")]"
DDETerminate chanNum
End Sub

hth
Norman Goetz
Norman Götz
 
S

Sathya

Thanks a lot Norman...This worked out..
Can u also tell me if there is anyother way other than DDE to pass the
value from EXCEL to WORD and VICE VERSA
Can this DDE be used for passing from word to excel also???
 
H

Howard Kaikow

Sathya said:
Can i add a menu item in excel thro word macros?
When the menu item is selected ..the activecell.value should be
available for word macro..
if i open an excel from word macro and try to capture activecell.value
..
Is this possible using word macro?

Yes.
 
C

Cindy M -WordMVP-

<[email protected]>
<[email protected]>
Newsgroups: microsoft.public.word.vba.general
NNTP-Posting-Host: 40.207.203.62.cust.bluewin.ch 62.203.207.40
Path: number1.nntp.ams.giganews.com!number1.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshub.sdsu.edu!msrtrans!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Lines: 1
Xref: number1.nntp.dca.giganews.com microsoft.public.word.vba.general:65741

Hi Sathya,
Can u also tell me if there is anyother way other than DDE to pass the
value from EXCEL to WORD and VICE VERSA
See how to run Excel from Word (and vice versa) on the word.mvps.org
website.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top