From: Jack on
Hi all,

This is no April fools question.
I'm using MS-Word to generate certain reports. After starting Word (as
shown below) I "write" some data to it to fill the report. This all
works fine.

METHOD PB_Afn_gen( ) CLASS Dlg_Mtp_Xtra
LOCAL template AS STRING

template:=cfgfile:GetString('Paths', 'Afn template')

SELF:oword:=OLEAutoObject{'word.application'}
IF !SELF:oword:fInit
WarningBox{SELF,'Start MS-Word', 'Kan MS-WORD niet
opstarten'}:show()
SELF:oword:=NULL_OBJECT
RETURN NIL
ENDIF


I'm keeping a link to the Word-object to retrieve the filename the
user used to store the document.

IF IVarGet(SELF:oword:documents, #count)>0
SELF:Store_AR(SELF:oword:ActiveDocument:FullName)
ENDIF

My problem arises when the user already closed MS-Word before he
clicks the button to retrieve the filename. How can I check if MS-Word
is still openend (or represents a valid object) ?

TIA,

Jack
From: Jean-Pierre Maertens on
Hallo,
Instead of working with OLEautoObject, you could generate a
Word-automation class. Then you could add this code to the
application-object

ACCESS NogActief CLASS MSApplication
LOCAL bFout AS CODEBLOCK
LOCAL bError AS CODEBLOCK
LOCAL lActief AS LOGIC

bFout:={|oError|MSWordFout(oError)}
bError:=ErrorBlock()
ErrorBlock(bFout)
BEGIN SEQUENCE
lActief:=TRUE
IF self:UserControl // als Word niet meer actief is krijgen we hier
een fout en springen we naar recover
ENDIF
RECOVER
lActief:=FALSE
END SEQUENCE
ErrorBlock(bError)

RETURN lActief

FUNCTION MSWordFout(oError)
// om te vermijden dat er een foutboodschap op het scherm komt
BREAK
RETURN FALSE




> Hi all,
>
> This is no April fools question.
> I'm using MS-Word to generate certain reports. After starting Word (as
> shown below) I "write" some data to it to fill the report. This all
> works fine.
>
> METHOD PB_Afn_gen( ) CLASS Dlg_Mtp_Xtra
> LOCAL template AS STRING
>
> template:=cfgfile:GetString('Paths', 'Afn template')
>
> SELF:oword:=OLEAutoObject{'word.application'}
> IF !SELF:oword:fInit
> WarningBox{SELF,'Start MS-Word', 'Kan MS-WORD niet
> opstarten'}:show()
> SELF:oword:=NULL_OBJECT
> RETURN NIL
> ENDIF
>
>
> I'm keeping a link to the Word-object to retrieve the filename the
> user used to store the document.
>
> IF IVarGet(SELF:oword:documents, #count)>0
> SELF:Store_AR(SELF:oword:ActiveDocument:FullName)
> ENDIF
>
> My problem arises when the user already closed MS-Word before he
> clicks the button to retrieve the filename. How can I check if MS-Word
> is still openend (or represents a valid object) ?
>
> TIA,
>
> Jack

--
Jean-Pierre Maertens


From: Jack Konings on
Hallo Zuiderbuur,

Thanks for your code. With a few modifications I was able to use it in my
own.


Happy eastern,

Jack


"Jean-Pierre Maertens" <jean-pierre.GEENSPAMmaertens(a)bruggeGEENSPAM.be>
wrote in message news:hp29am$bot$1(a)ikarus.fw.belnet.be...
> Hallo,
> Instead of working with OLEautoObject, you could generate a
> Word-automation class. Then you could add this code to the
> application-object
>
> ACCESS NogActief CLASS MSApplication
> LOCAL bFout AS CODEBLOCK
> LOCAL bError AS CODEBLOCK
> LOCAL lActief AS LOGIC
>
> bFout:={|oError|MSWordFout(oError)}
> bError:=ErrorBlock()
> ErrorBlock(bFout)
> BEGIN SEQUENCE
> lActief:=TRUE
> IF self:UserControl // als Word niet meer actief is krijgen we hier een
> fout en springen we naar recover
> ENDIF
> RECOVER
> lActief:=FALSE
> END SEQUENCE
> ErrorBlock(bError)
>
> RETURN lActief
>
> FUNCTION MSWordFout(oError)
> // om te vermijden dat er een foutboodschap op het scherm komt
> BREAK
> RETURN FALSE
>
>
>
>
>> Hi all,
>>
>> This is no April fools question.
>> I'm using MS-Word to generate certain reports. After starting Word (as
>> shown below) I "write" some data to it to fill the report. This all
>> works fine.
>>
>> METHOD PB_Afn_gen( ) CLASS Dlg_Mtp_Xtra
>> LOCAL template AS STRING
>>
>> template:=cfgfile:GetString('Paths', 'Afn template')
>>
>> SELF:oword:=OLEAutoObject{'word.application'}
>> IF !SELF:oword:fInit
>> WarningBox{SELF,'Start MS-Word', 'Kan MS-WORD niet
>> opstarten'}:show()
>> SELF:oword:=NULL_OBJECT
>> RETURN NIL
>> ENDIF
>>
>>
>> I'm keeping a link to the Word-object to retrieve the filename the
>> user used to store the document.
>>
>> IF IVarGet(SELF:oword:documents, #count)>0
>> SELF:Store_AR(SELF:oword:ActiveDocument:FullName)
>> ENDIF
>>
>> My problem arises when the user already closed MS-Word before he
>> clicks the button to retrieve the filename. How can I check if MS-Word
>> is still openend (or represents a valid object) ?
>>
>> TIA,
>>
>> Jack
>
> --
> Jean-Pierre Maertens
>
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus
> signature database 4993 (20100401) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>
From: Mike Scholl on
Jack

What I do is to get the filename using SaveAsDialog before opening Word and
then use SaveAs to save it

oSaveWin :=
SaveAsDialog{SELF,DToS(SELF:oDCbBrowser1:Server:StartDate)+AllTrim(oAddr:Christian)+AllTrim(oAddr:Surname)+"Agreement.doc"}
oSaveWin:Show()
cFileName := oSaveWin:FileName
IF Empty(cFileName)
RETU
ELSEIF File(cFileName)
IF Textbox{,"Overwrite Existing File","File "+cFileName +" exists
already",BUTTONYESNO+BOXICONQUESTIONMARK}:show() <> BOXREPLYYES
RETU
ENDIF
ENDIF
oPointer := SELF:Pointer
SELF:Pointer := Pointer{POINTERHOURGLASS}
SELF:owner:StatusMessage("connecting to Word",MESSAGEPERMANENT )
//make OLE connection to Word
oWord := OleAutoObject{"word.application"}
oWord:visible :=TRUE
//New document base on template
SELF:owner:StatusMessage(Hyperlabel{#WORDOLE,"Word OLE" ,"creating new
Word Document"},MESSAGEPERMANENT )
oDocument := oWord:Documents:Add( cTemplate, FALSE)

//Put data into Word document
SELF:owner:StatusMessage(Hyperlabel{#WORDOLE,"Word OLE" ,"Filling document
with data"},MESSAGEPERMANENT )
SELF:FillBookmarks(oDocument) // this is my method to put text into the
document
//Save file in std format
SELF:Pointer := oPointer
SELF:owner:StatusMessage("saving document",MESSAGEPERMANENT )
oDocument:SaveAs(cFileName)

But the Word Automation class may be a better solution

Mike


"Jack" <jack.konings(a)dsm.com> wrote in message
news:b33d33df-55d6-4863-aa37-a5e4e5e4022d(a)j21g2000yqh.googlegroups.com...
> Hi all,
>
> This is no April fools question.
> I'm using MS-Word to generate certain reports. After starting Word (as
> shown below) I "write" some data to it to fill the report. This all
> works fine.
>
> METHOD PB_Afn_gen( ) CLASS Dlg_Mtp_Xtra
> LOCAL template AS STRING
>
> template:=cfgfile:GetString('Paths', 'Afn template')
>
> SELF:oword:=OLEAutoObject{'word.application'}
> IF !SELF:oword:fInit
> WarningBox{SELF,'Start MS-Word', 'Kan MS-WORD niet
> opstarten'}:show()
> SELF:oword:=NULL_OBJECT
> RETURN NIL
> ENDIF
>
>
> I'm keeping a link to the Word-object to retrieve the filename the
> user used to store the document.
>
> IF IVarGet(SELF:oword:documents, #count)>0
> SELF:Store_AR(SELF:oword:ActiveDocument:FullName)
> ENDIF
>
> My problem arises when the user already closed MS-Word before he
> clicks the button to retrieve the filename. How can I check if MS-Word
> is still openend (or represents a valid object) ?
>
> TIA,
>
> Jack