# Calling MS Winword from Natural

**URL:** <https://techcommunity.softwareag.com/t/calling-ms-winword-from-natural/60745>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-Code-Samples\
**Created:** [March 30, 2006, 9:52pm UTC](https://techcommunity.softwareag.com/t/calling-ms-winword-from-natural/60745 "2006-03-30T21:52:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexey](https://avatars.discourse-cdn.com/v4/letter/a/47e85d/32.png) [@Alexey](https://techcommunity.softwareag.com/u/Alexey)\
**Post date:** [March 30, 2006, 9:52pm UTC](https://techcommunity.softwareag.com/t/calling-ms-winword-from-natural/60745/1 "2006-03-30T21:52:39Z")

</div>

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

```auto

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
```

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [March 31, 2006, 8:45pm UTC](https://techcommunity.softwareag.com/t/calling-ms-winword-from-natural/60745/2 "2006-03-31T20:45:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 9, 2008, 8:47pm UTC](https://techcommunity.softwareag.com/t/calling-ms-winword-from-natural/60745/3 "2008-04-09T20:47:07Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 2:40pm UTC](https://techcommunity.softwareag.com/t/calling-ms-winword-from-natural/60745/4 "2021-04-02T14:40:32Z")

</div>


