In Microsoft Excel, you can write a macro that will open and close
Microsoft Word for Windows from Microsoft Excel. To create this macro,
do the following:
- Write a macro that will create an open channel number.
- Run Word for Windows.
- Close Word for Windows.
- Close the open channel number.
Microsoft provides macro examples for illustration only, without warranty
either expressed or implied, including but not limited to the implied
warranties of merchantability and/or fitness for a particular purpose. This
macro is provided 'as is' and Microsoft does not guarantee that the
following code can be used in all situations. Microsoft does not support
modifications of the code to suit customer requirements.
Sample Macro 1
The following sample Microsoft Excel macro, starts Word for Windows,
initiates a DDE channel using the topic "System," and terminates the open
channel number:
A1: =EXEC("winword")
A2: =INITIATE("winword","system")
A3: =EXECUTE(A2,"[FileExit(1)]")
A4: =TERMINATE(A2)
A5: =RETURN()
NOTE: This macro assumes that Word for Windows is in your path.
Sample Macro 2
The following Microsoft Excel macro, initiates a DDE Channel to Microsoft
Word for Windows. In addition, it checks to see if Word for Windows is
currently running. If it is, the macro initiates the channel to the current
session of Word. This eliminates the problem of multiple instances of Word
for Windows being opened unnecessarily. If Word for Windows is not running
the macro starts Word.
A1: =SET.NAME("HANDLE",REGISTER("kernel","getModuleHandle","IC"))
A2: =SET.NAME("CALLVALUE",CALL(Handle,"WINWORD.EXE"))
A3: =IF(CallValue=0)
A4: =EXEC("WINWORD.EXE")
A5: =END.IF()
A6: =INITIATE("WINWORD","SYSTEM")
A7: =RETURN()
Note: this is also true for Microsoft Excel version 5.0 macro sheets when
you use version 4.0 macros.