The information in this article applies to:
SUMMARY
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.
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.
In the example above, Word must be running and the Sales.doc document must
be open for the DDEInitiate command to return without error and with a
valid channel number.
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:
Example:
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.
NOTE: Word operates the same with the exception of the DDEExecute
statement to open the file. We do not demonstrate this with Word
communicating with a second instance since the system topic always finds
the client instance, the second instance is ignored. Any attempt to do a
DDEExecute to the same instance of Word results in an error. A single
instance of Word cannot be both the client and server in a DDE
conversation. If this were possible, the exe$ variable would be set to
the following:
REFERENCES"Microsoft Word Technical Reference for Windows and OS/2," pages 307-312. Additional query words: dynamic data exchange ole object linking embedding appnote wordbasic
Keywords : kbmacro kbole wordnt word8 kbwordvba winword word97 word6 winword2 word7 word95 |
Last Reviewed: September 22, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |