Calling MS Winword from Natural

In case somebody needs to use MS Winword in Natural program
here is small example…


DEFINE DATA LOCAL
1 #myWordApplication HANDLE OF OBJECT
1 #myWordFile        HANDLE OF OBJECT
1 #WDocuments        HANDLE OF OBJECT
1 #mySelection       HANDLE OF OBJECT
1 #end (a1)
1 #fileName (a20) init <'d:\123.doc'>
1 #dummy (a20)
END-DEFINE

repeat while #end <> '6'
input /
      / '(0) Create new winword doc'
      / '(1) Open existing winword file' #fileName (ad=m)
      / '(2) Show Winword editor'
      / '(3) Hide Winword  editor'
      / '(4) Insert some data in current document'
      / '(5) Print document'
      / '(6) End program'
      / '    What do you want to do today (0-6)' #end

if #end = '0' then
   CREATE OBJECT #myWordApplication OF CLASS "Word.Application"
   #WDocuments := #myWordApplication.Documents
   SEND "Add" TO #WDocuments with #filename
       RETURN #myWordFile
       move #myWordFile.name to #dummy
       write '&#1054;&#1090;&#1082;&#1088;&#1099;&#1090;&#1099;&#1081; &#1092;&#1072;&#1081;&#1083;' #dummy
end-if

if #end = '1' then
   CREATE OBJECT #myWordApplication OF CLASS "Word.Application"
   #WDocuments := #myWordApplication.Documents
   SEND "Open" TO #WDocuments with #filename
       RETURN #myWordFile
       move #myWordFile.name to #dummy
       write 'opened file name' #dummy
end-if


if #end = '2' then
 move true to #myWordApplication.<<Visible>> /* &#1087;&#1086;&#1082;&#1072;&#1078;&#1077;&#1084; &#1085;&#1072; &#1101;&#1082;&#1088;&#1072;&#1085;&#1077;
end-if

if #end = '3' then
 move false to #myWordApplication.<<Visible>> /* &#1089;&#1087;&#1088;&#1103;&#1095;&#1077;&#1084;
end-if

if #end = '4' then
 send "Selection" to #myWordApplication return #mySelection
 send "TypeText" to #mySelection with '&#1087;&#1088;&#1080;&#1074;&#1077;&#1090;'
end-if

if #end = '5' then
send "PrintOut" to #myWordApplication     /* &#1087;&#1077;&#1095;&#1072;&#1090;&#1072;&#1077;&#1084;
end-if

if #end = '6' then
   SEND "quit" TO #myWordApplication with false /* &#1089;&#1086;&#1093;&#1088;&#1072;&#1085;&#1103;&#1090;&#1100; &#1085;&#1077; &#1073;&#1091;&#1076;&#1077;&#1084;
   #myWordApplication := null-handle
end-if

end-repeat

end

Or, if you just want to start up Word:

DEFINE DATA LOCAL
1 USR1052L
2 OS-COMMAND (A253)
2 RESPONSE (I4)
END-DEFINE
*
MOVE ‘c:\PROGRAM FILES\MICROSOFT OFFICE\OFFICE\WINWORD’
TO OS-COMMAND
CALLNAT ‘USR1052N’ USR1052L

USR1052L lets you issue any OC command.

steve

Surely the first way of activating MS Word is the preferred one?

It does isolate you from such technicalities of the location of the word.exe and whatever other environment settings that you might have to set-up using Steve’s solution. Or am I missing the plot?