Sybase NNTP forums - End Of Life (EOL)

The NNTP forums from Sybase - forums.sybase.com - are now closed.

All new questions should be directed to the appropriate forum at the SAP Community Network (SCN).

Individual products have links to the respective forums on SCN, or you can go to SCN and search for your product in the search box (upper right corner) to find your specific developer center.

Close Word Programatically

2 posts in Objects Last posting was on 2003-02-14 06:51:16.0Z
Bobby Posted on 2003-02-13 18:29:03.0Z
Newsgroups: sybase.public.powerbuilder.objects
From: Bobby
Date: Thu, 13 Feb 2003 13:29:03 -0500
Subject: Close Word Programatically
Lines: 8
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Message-ID: <364_D48AD7DD95AD02010065898685256CCC.0065899585256CCC@webforums>
Path: forums-1-dub!forums-1-dub!forums-master.sybase.com!forums.sybase.com!webforums.sybase.com!news
Xref: forums-1-dub sybase.public.powerbuilder.objects:110
Article PK: 712681

I'm running my application on PB 8.0. In a window to export some data into
a file, I want to open Microsoft Word from the application, and then close
it when the export is done

I've managed to use Run("C:\Program Files\Microsoft
Office\Office\WINWORD.EXE") which opens Word. How do I close Word
programatically. Please Help

Bobby


"De Permentier Davy" <no_spam Posted on 2003-02-14 06:51:16.0Z
Newsgroups: sybase.public.powerbuilder.objects
From: "De Permentier Davy" <no_spam@my_adress>
Subject: Re: Close Word Programatically
Date: Fri, 14 Feb 2003 07:51:16 +0100
Lines: 170
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 193.190.121.69
Message-ID: <364_kWQnug$0CHA.351@forums.sybase.com>
References: <364_D48AD7DD95AD02010065898685256CCC.0065899585256CCC@webforums>
Path: forums-1-dub!forums-1-dub!forums-master.sybase.com!forums.sybase.com
Xref: forums-1-dub sybase.public.powerbuilder.objects:105
Article PK: 712680

Hey,

You might want to use Ole...
Here's some sample code for how to do some basic stuff

HTH,
Davy

Instance variables
OleObject iOLE_word, iOLE_doc
BOOLEAN ib_connected = FALSE


public function integer f_set_bookmark (string as_bookmark, string
as_value);

IF NOT ib_connected THEN RETURN -1

iOLE_word.Application.ActiveDocument.BookMarks.Item(as_bookmark).Select
iOLE_word.application.Selection.TypeText(as_value)

RETURN 1

----------------------------------

public function integer f_set_bookmark (string as_bookmark[], string
as_value[]);

Long ll_count, ll_upperbound_bookmark, ll_upperbound_value

IF NOT ib_connected THEN RETURN -1

ll_upperbound_bookmark = UpperBound(as_bookmark)
ll_upperbound_value = UpperBound(as_value)

IF NOT IsNull(ll_upperbound_bookmark) AND NOT IsNull(ll_upperbound_value)
THEN
IF ll_upperbound_bookmark = ll_upperbound_value THEN
FOR ll_count = 1 TO ll_upperbound_bookmark
This.f_set_bookmark(as_bookmark[ll_count], as_value[ll_count])
NEXT
RETURN 1
END IF
END IF

----------------------------------

public function integer f_save_as_document (string as_doc);

//as_doc must contain the full path !

IF NOT ib_connected THEN RETURN -1

iOLE_word.Application.ActiveDocument.SaveAs(as_doc)

RETURN 1

-----------------------------------

public function integer f_disconnect ();

Integer li_rt

IF NOT ib_connected THEN RETURN 0

iOLE_word.Application.Quit

li_rt = iOLE_word.DisconnectObject()

CHOOSE CASE li_rt
CASE -1
//Invalid call: the argument is the Object property of a control
RETURN -1
CASE -9
//Other error
RETURN -1
END CHOOSE

ib_connected = FALSE

RETURN 1

-----------------------------------------

public function integer f_open_document (string as_doc);

Integer li_rt

IF NOT ib_connected THEN RETURN -1

//Open Word Document
iOLE_word.Documents.Open(as_doc)

RETURN 1

-------------------------------------------

public function integer f_set_word_visible (boolean ab_visible);

IF NOT ib_connected THEN RETURN -1

iOLE_word.Visible = ab_visible

RETURN 1

--------------------------------------------

public function integer f_connect (string as_doc, boolean ab_visible);

Integer li_rt

IF ib_connected THEN RETURN 0

iOLE_word = CREATE OleObject

li_rt = iOLE_word.ConnectToNewObject("word.application.9")

CHOOSE CASE li_rt
CASE -1
//Invalid call: the argument is the Object property of a control
RETURN -1
CASE -2
//Class name not found
RETURN -1
CASE -3
//Object could not be created
RETURN -1
CASE -4
//Could not connect to object
RETURN -1
CASE -9
//Other error
RETURN -1
CASE -15
//MTS is not loaded on this computer
RETURN -1
CASE -16
//Invalid Call: this function not applicable to OLETxnObject
RETURN -1
CASE ELSE
ib_connected = TRUE
END CHOOSE

This.f_set_word_visible( TRUE )

//Open document
This.f_open_document( as_doc )

//Activate Word application
iOLE_word.Activate

//Set Visbility
This.f_set_word_visible( ab_visible )

RETURN 1

<Bobby> wrote in message
news:D48AD7DD95AD02010065898685256CCC.0065899585256CCC@webforums...
> I'm running my application on PB 8.0. In a window to export some data into
> a file, I want to open Microsoft Word from the application, and then close
> it when the export is done
>
> I've managed to use Run("C:\Program Files\Microsoft
> Office\Office\WINWORD.EXE") which opens Word. How do I close Word
> programatically. Please Help
>
> Bobby