ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   DDE Argument exchange with Word (https://www.excelbanter.com/excel-programming/290442-dde-argument-exchange-word.html)

steve

DDE Argument exchange with Word
 
Does anyone know how to send a variable text string from
Excel to Word using a DDE argument in an Excel macro? The
following Excel macro will send a specific text string,
but I want to use a variable to define the text string.



Sub WordOpen(customerName)
'
'

Dim WordApp As Object
Dim WordDoc As Word.Document
Dim Chan As Variant

Dim PathName, FileName As String


PathName = ActiveWorkbook.Path
FileName = PathName & "\Test.doc"


Set WordApp = CreateObject("Word.Application")
Set WordDoc = WordApp.Documents.Open(FileName)
WordApp.Visible = True

' Initiate a channel with Microsoft Word.
Chan = DDEInitiate("WinWord", FileName)

' This sends the text to Word
DDEExecute Chan, "[Module1.Begin(""John Doe"")]"

' Want a command to send variable text customerName to
Word, similar to this except it does not work
' DDEExecute Chan, "[Module1.Begin(customerName)]"

' Terminate the channel.
DDETerminate Chan


'
End Sub



All times are GMT +1. The time now is 07:03 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com