Article ID: 93657 - Last Review: January 18, 2007 - Revision: 2.3 WD: Running Word for Windows as a DDE Server
This article was previously published under Q93657 On This PageSUMMARY
This article covers what DDE topics and items are used to communicate with
Word for Windows as a DDE server. This article assumes that you have a
working knowledge of DDE concepts.
Word for Windows sample macros are provided to demonstrate the DDE server functionality. NOTE: Some DDE functions do not work correctly when executed from a single instance of Word for Windows. In other words, a single copy of Word cannot be both the client and the server in a DDE conversation at the same time. For the macro examples below, run two copies of Word for Windows simultaneously with one being the client and the other the server. Word 2.x: You must have the MS-DOS SHARE command line present in your AUTOEXEC.BAT file to have two copies of Word running simultaneously. Word 1.x: You must make a copy of the WINWORD.EXE file on your system and rename this copy to something else. The two copies can be run with one as the client and the other the server. MORE INFORMATIONWord 97For more information about and examples using DDE with Word 97, while in the Visual Basic for Applications Editor click the Office Assistant, type "DDE," click Search, and then click to view "Communicating with other applications."Word for Windows versions 2.x, 6.x, 7.xInitiating a DDE Conversation with Word As a ServerWhen you initiate a DDE conversation with another application, or "dial up" the other application, two things are required--an "application" name and the "topic" of the conversation.The "application" name is typically the name of the program's executable file. For Word, the application name is WINWORD. The "topic" of a DDE conversation can be either the name of a currently open document or the special topic "system". A document can be either a regular Word document, a template, or a macro. See "Using the System Topic" for more information about the system topic. Example: The following macro demonstrates initiating a conversation with a document as the topic. Poking Data into and Requesting Data from a Word DocumentTo poke (send) or request information from a DDE topic, an "item" must be specified. The item represents the specific piece of data or location in the topic where data will be sent to or retrieved from. If a Word document is the topic of the DDE conversation, the item is a piece of text or location that has been bookmarked using the Insert Bookmark command.NOTE: Word has a number of reserved bookmark names, such as \sel and \page, that cannot be used in a DDE conversation. Only bookmarks that have been inserted using the Insert Bookmark command can be used. Example: The following macro demonstrates poking to and requesting data and from a Word document:
Sending Keystrokes to Word for WindowsIt is possible to send data to Word without using a DDE Poke. If you perform a DDE Execute and do not put square brackets around the execute string, Word types them into the document at the current cursor location. Further, you can have Word perform special key commands, such as pressing the ENTER key or SHIFT+F3, by following the key syntax used in the WordBasic SendKeys macro command.Example: The following macro types five lines of data into the document Sales.doc at the current cursor location: Using the System TopicThe system topic is a special topic supported by most DDE-aware applications to allow the client to obtain specific information about the current status of the server. The most common purpose is to get a list of available topics that can be used to initiate a conversation, or to see if the desired topic is available for use.Once a DDE conversation with Word as the server has been initiated using the system topic, a DDE request can be performed using the following items: SysItems, Topics, and Formats. The list of information returned by this DDE request will be tab delimited. The following table summarizes the available information:
Item Available Information
-------- ---------------------
SysItems A list of all items you can use with the "system" topic.
Topics A list of all topics used to initiate a DDE conversation.
This includes a list of all currently open documents with
their path names, templates, macro windows, and the system
topic.
Formats A list of all the Clipboard formats supported by Word.
The following macro uses the system topic to get information on all three system items: SysItems, Topics, and Formats. The macro parses the tab- delimited list of information, putting it into an array for display in a custom dialog box. System Topic PitfallsThe system topic was designed primarily for use in retrieving information about Word using the SysItems, Topics, and Formats items.However, some users may be tempted to use it for doing other activities, such as DDE pokes and requests to bookmarks in open documents, or performing DDE executes of macro instructions. The problem is that most Word commands that can be executed must be directed toward a specific document. Because Word can have up to nine document windows open at a time, if you try to do a DDE execute to insert some text into a document using the system topic, Word doesn't know which open document to insert the text into (Word doesn't assume that the active window is the desired window). Attempting to execute document-specific commands with the system topic results in an error. The same holds true if you attempt to request data from an item not supported by the system topic described above. Commands that are executed that are not document-specific, like opening or creating a new document, work fine. In fact, a common practice among macro writers is to use the Topics item to see if the desired document is available to communicate with. If the document is not available, you can execute the FileOpen command to open it. After the document (topic) is open, you close the communication with the system topic and then initiate a new conversation with the open document. The following macro demonstrates this technique using Microsoft Excel. Example: The following macro demonstrates using the system topic in Microsoft Excel to determine if a particular spreadsheet is open and available for a DDE conversation. If it is not, a DDEExecute is issued to Excel to open the spreadsheet. "[FileOpen " + Chr$(34) + Topic$ + Chr$(34) + "]" REFERENCES
"Microsoft Word Technical Reference for Windows and OS/2," pages 307-312.
APPLIES TO
| Other Resources Other Support Sites
CommunityGet Help NowArticle Translations
|






Windows Live
Facebook
Twitter
Linkedin
Digg it
Yahoo
Delicious
StumbleUpon
Yammer
Reddit
Technorati
FriendFeed
Email

Back to the top
