Skip to main content

Prezados Amigos,

Usei este programa como exemplo para gerar documentos no Microsoft Word:

$set ooctrl( P) ooctrl( Q)
*copy "word.if". *> Word vocavularies
*copy "excel.if". *> Excel vocabularies
program-id. WORDAPI.
special-names. call-convention 2 is WinApi.

Class-Control.
*-------------

WordApp is class "$OLE$word.application". *> Word 97

Working-Storage Section.
*------------------------------
77 j pic 9(003).
77 k pic 9(003).
77 wChar pic X(001).

01 WordServer object reference value null.
01 theDocuments object reference value null.
01 theDocument object reference value null.
01 theSelection object reference value null.
01 theReplacement object reference value null.
01 theParagraphs object reference value null.
01 theParagraph object reference value null.
01 theRange object reference value null.
01 theFind object reference value null.

01 wText pic X(255).

01 found pic x comp-5.
88 found-True value 45.
88 found-False value 48.

01 Program-Flags pic 9(2) comp-5 value 1.
88 New-Instance value 1 false 0.

Linkage Section.
*----------------
01 wrdParam.
05 wrdOperation pic x(008).
05 wrdFileName pic x(255).
05 wrdText pic x(255).
05 wrdChange2 pic x(255).
05 wrdSearchStatus pic x(002).
05 wordVisible pic s9(001).
05 wordSaveMode pic s9(001).

Procedure Division Using wrdParam.
******************************************************************
*
* If New-Instance
* Perform New-Set-Instance
* End-if

Evaluate wrdOperation
When 'Create'
Perform Create-Aplication
When 'Open'
Perform File-Open
When 'Delete'
Perform Delete-Selection
When 'Insert'
Perform Insert-Text
When 'Find'
Perform Find-Text
When 'Replace'
Perform Replace-Text
When 'FReplace'
* Perform Find-and-Replace-Text
Perform Find-Text
Perform Replace-Text
When 'Preview'
Perform Print-Preview
When 'Print'
Perform Print-Document
When 'Quit'
Perform Quit-Set-Instance
End-Evaluate

Exit Program
.
*----------------------------------------------------------------
Create-Aplication Section.

*> Criar uma instancia do Word
Invoke wordapp "new" Returning wordServer

*> Pega o objeto de coleção Word documents
Invoke wordServer "getDocuments" Returning theDocuments

*> Seta se o Word será visualizado
invoke wordServer "SetVisible" using by value wordVisible
.
*----------------------------------------------------------------
File-Open Section.

*> Abre o arquivo em wrdFileName
Invoke theDocuments "Open" Using wrdFileName

*> Pega o documento ativo
Invoke wordServer "getActiveDocument" Returning theDocument
.
*----------------------------------------------------------------
Delete-Selection Section.

* invoke wordServer "getSelection" returning theSelection
* invoke theSelection "Delete"

*> Seleciona o texto encontrado
invoke theRange "select"

*> 'CUTila' o texto encontrado
invoke theRange "Cut"
.
*----------------------------------------------------------------
Insert-Text Section.

* Move wrdChange2 to wText

* Perform Null-Terminate-Routine
* Move wText to wrdChange2
* invoke wordServer "getSelection" returning theSelection
* invoke theSelection "InsertAfter" using by content wrdChange2

*> Insere o texto
invoke theRange "InsertAfter" using by content wrdChange2
.
*----------------------------------------------------------------
Find-Text Section.

Move "23" to wrdSearchStatus
Move wrdText to wText

Perform Null-Terminate-Routine

Move wText to wrdText

*> Pega o objeto Range
Invoke theDocument "getContent" returning theRange

*> Pega o objecto Find
Invoke theRange "getFind" returning theFind

*> A procura será para frente
Invoke theFind "setForward" using by value 1

*> A busca sera pelo conteudo de wrdText
Invoke theFind "setText" using by content wrdText

*> Procurar
Invoke theFind "execute"

*> Encontrou ?
Invoke theFind "getFound" returning found

*> Se encontrou...
if found-True
move "00" to wrdSearchStatus
end-if
.
*----------------------------------------------------------------
Find-and-Replace-Text Section.

Move "23" to wrdSearchStatus
Move wrdText to wText

Perform Null-Terminate-Routine

Move wText to wrdText
Move wrdChange2 to wText

Perform Null-Terminate-Routine

Move wText to wrdChange2

*> Pega o objeto Range
Invoke theDocument "getContent" returning theRange

*> Pega o objecto Find
Invoke theRange "getFind" Returning theFind

*> A procura será para frente
Invoke theFind "getReplacement" Returning theReplacement

Invoke theFind "setForward" Using by value 1
*> A busca sera pelo conteudo de wrdText

Invoke theFind "setText" Using by content wrdText
Invoke theReplacement "setText" Using by content wrdChange2

*> Procurar
* Invoke theFind "setReplace" Using by value 1
Invoke theFind "execute"

*> Encontrou ?
Invoke theFind "getFound" returning found

*> Se encontrou...
if found-True
move "00" to wrdSearchStatus
end-if
.
*----------------------------------------------------------------
Replace-Text Section.

Move wrdChange2 to wText

Perform Null-Terminate-Routine

Move wText to wrdChange2
subtract 01 from k

*> Seleciona o texto encontrado
invoke theRange "select"

*> Finalmente, muda o texto encontrado (wrdText)
*> para o desejado
invoke theRange "Cut"
move 00 to j
invoke theRange "InsertAfter" using " "
perform until j = k
add 01 to j
move wrdChange2(j:1) to wChar
invoke theRange "InsertAfter" using by content wChar
end-perform

*> Não preciso mais dos objetos Find e Range
Invoke theFind "finalize" returning theFind
Invoke theRange "finalize" returning theRange
.
*----------------------------------------------------------------
Print-Preview Section.

invoke theDocument "PrintPreview"
.
*----------------------------------------------------------------
Print-Document Section.

invoke theDocument "PrintOut" using by value 0
.
*----------------------------------------------------------------
New-Set-Instance Section.

set New-Instance to false
.
*----------------------------------------------------------------
Null-Terminate-Routine Section.

move length of wText to j

perform varying k from j by -1
until k = 0

if wText(k:1) not = spaces and not = X"00"
add 01 to k
move x"00" to wText(k:1)
exit section
end-if

end-perform

move x"00" to wText(j:1)
.
*----------------------------------------------------------------
Size-Of-String Section.

move length of wText to j

perform varying k from j by -1
until k = 0
or wtext(k:1) not = spaces and x"00"
end-perform
.
*----------------------------------------------------------------
Quit-Set-Instance Section.

*> Fechar o arquivo sem salvando-o
if wordSaveMode = 0
Invoke theDocument "Close" Using by value 0
else
if wordSaveMode = -1
Invoke theDocument "Close" Using by value -1
end-if
end-if

*> Finalizar o objecto de coleção Documents
Invoke theDocuments "finalize" Returning theDocuments

*> Tell Word to quit (it won't shut down otherwise)
Invoke wordServer "quit"

*> Finalizar o Word
Invoke wordServer "finalize" Returning wordServer
.

1 - Como descubro todos os métodos da classe wordapp ?

2 - Onde encontro o arquivo "word.if" , definido no inicio do programa ?

Atenciosamente

Rogerio Barbosa Ferreira

Prezados Amigos,

Usei este programa como exemplo para gerar documentos no Microsoft Word:

$set ooctrl( P) ooctrl( Q)
*copy "word.if". *> Word vocavularies
*copy "excel.if". *> Excel vocabularies
program-id. WORDAPI.
special-names. call-convention 2 is WinApi.

Class-Control.
*-------------

WordApp is class "$OLE$word.application". *> Word 97

Working-Storage Section.
*------------------------------
77 j pic 9(003).
77 k pic 9(003).
77 wChar pic X(001).

01 WordServer object reference value null.
01 theDocuments object reference value null.
01 theDocument object reference value null.
01 theSelection object reference value null.
01 theReplacement object reference value null.
01 theParagraphs object reference value null.
01 theParagraph object reference value null.
01 theRange object reference value null.
01 theFind object reference value null.

01 wText pic X(255).

01 found pic x comp-5.
88 found-True value 45.
88 found-False value 48.

01 Program-Flags pic 9(2) comp-5 value 1.
88 New-Instance value 1 false 0.

Linkage Section.
*----------------
01 wrdParam.
05 wrdOperation pic x(008).
05 wrdFileName pic x(255).
05 wrdText pic x(255).
05 wrdChange2 pic x(255).
05 wrdSearchStatus pic x(002).
05 wordVisible pic s9(001).
05 wordSaveMode pic s9(001).

Procedure Division Using wrdParam.
******************************************************************
*
* If New-Instance
* Perform New-Set-Instance
* End-if

Evaluate wrdOperation
When 'Create'
Perform Create-Aplication
When 'Open'
Perform File-Open
When 'Delete'
Perform Delete-Selection
When 'Insert'
Perform Insert-Text
When 'Find'
Perform Find-Text
When 'Replace'
Perform Replace-Text
When 'FReplace'
* Perform Find-and-Replace-Text
Perform Find-Text
Perform Replace-Text
When 'Preview'
Perform Print-Preview
When 'Print'
Perform Print-Document
When 'Quit'
Perform Quit-Set-Instance
End-Evaluate

Exit Program
.
*----------------------------------------------------------------
Create-Aplication Section.

*> Criar uma instancia do Word
Invoke wordapp "new" Returning wordServer

*> Pega o objeto de coleção Word documents
Invoke wordServer "getDocuments" Returning theDocuments

*> Seta se o Word será visualizado
invoke wordServer "SetVisible" using by value wordVisible
.
*----------------------------------------------------------------
File-Open Section.

*> Abre o arquivo em wrdFileName
Invoke theDocuments "Open" Using wrdFileName

*> Pega o documento ativo
Invoke wordServer "getActiveDocument" Returning theDocument
.
*----------------------------------------------------------------
Delete-Selection Section.

* invoke wordServer "getSelection" returning theSelection
* invoke theSelection "Delete"

*> Seleciona o texto encontrado
invoke theRange "select"

*> 'CUTila' o texto encontrado
invoke theRange "Cut"
.
*----------------------------------------------------------------
Insert-Text Section.

* Move wrdChange2 to wText

* Perform Null-Terminate-Routine
* Move wText to wrdChange2
* invoke wordServer "getSelection" returning theSelection
* invoke theSelection "InsertAfter" using by content wrdChange2

*> Insere o texto
invoke theRange "InsertAfter" using by content wrdChange2
.
*----------------------------------------------------------------
Find-Text Section.

Move "23" to wrdSearchStatus
Move wrdText to wText

Perform Null-Terminate-Routine

Move wText to wrdText

*> Pega o objeto Range
Invoke theDocument "getContent" returning theRange

*> Pega o objecto Find
Invoke theRange "getFind" returning theFind

*> A procura será para frente
Invoke theFind "setForward" using by value 1

*> A busca sera pelo conteudo de wrdText
Invoke theFind "setText" using by content wrdText

*> Procurar
Invoke theFind "execute"

*> Encontrou ?
Invoke theFind "getFound" returning found

*> Se encontrou...
if found-True
move "00" to wrdSearchStatus
end-if
.
*----------------------------------------------------------------
Find-and-Replace-Text Section.

Move "23" to wrdSearchStatus
Move wrdText to wText

Perform Null-Terminate-Routine

Move wText to wrdText
Move wrdChange2 to wText

Perform Null-Terminate-Routine

Move wText to wrdChange2

*> Pega o objeto Range
Invoke theDocument "getContent" returning theRange

*> Pega o objecto Find
Invoke theRange "getFind" Returning theFind

*> A procura será para frente
Invoke theFind "getReplacement" Returning theReplacement

Invoke theFind "setForward" Using by value 1
*> A busca sera pelo conteudo de wrdText

Invoke theFind "setText" Using by content wrdText
Invoke theReplacement "setText" Using by content wrdChange2

*> Procurar
* Invoke theFind "setReplace" Using by value 1
Invoke theFind "execute"

*> Encontrou ?
Invoke theFind "getFound" returning found

*> Se encontrou...
if found-True
move "00" to wrdSearchStatus
end-if
.
*----------------------------------------------------------------
Replace-Text Section.

Move wrdChange2 to wText

Perform Null-Terminate-Routine

Move wText to wrdChange2
subtract 01 from k

*> Seleciona o texto encontrado
invoke theRange "select"

*> Finalmente, muda o texto encontrado (wrdText)
*> para o desejado
invoke theRange "Cut"
move 00 to j
invoke theRange "InsertAfter" using " "
perform until j = k
add 01 to j
move wrdChange2(j:1) to wChar
invoke theRange "InsertAfter" using by content wChar
end-perform

*> Não preciso mais dos objetos Find e Range
Invoke theFind "finalize" returning theFind
Invoke theRange "finalize" returning theRange
.
*----------------------------------------------------------------
Print-Preview Section.

invoke theDocument "PrintPreview"
.
*----------------------------------------------------------------
Print-Document Section.

invoke theDocument "PrintOut" using by value 0
.
*----------------------------------------------------------------
New-Set-Instance Section.

set New-Instance to false
.
*----------------------------------------------------------------
Null-Terminate-Routine Section.

move length of wText to j

perform varying k from j by -1
until k = 0

if wText(k:1) not = spaces and not = X"00"
add 01 to k
move x"00" to wText(k:1)
exit section
end-if

end-perform

move x"00" to wText(j:1)
.
*----------------------------------------------------------------
Size-Of-String Section.

move length of wText to j

perform varying k from j by -1
until k = 0
or wtext(k:1) not = spaces and x"00"
end-perform
.
*----------------------------------------------------------------
Quit-Set-Instance Section.

*> Fechar o arquivo sem salvando-o
if wordSaveMode = 0
Invoke theDocument "Close" Using by value 0
else
if wordSaveMode = -1
Invoke theDocument "Close" Using by value -1
end-if
end-if

*> Finalizar o objecto de coleção Documents
Invoke theDocuments "finalize" Returning theDocuments

*> Tell Word to quit (it won't shut down otherwise)
Invoke wordServer "quit"

*> Finalizar o Word
Invoke wordServer "finalize" Returning wordServer
.

1 - Como descubro todos os métodos da classe wordapp ?

2 - Onde encontro o arquivo "word.if" , definido no inicio do programa ?

Atenciosamente

Rogerio Barbosa Ferreira

Hi Rogerio,

For documentation on the Word Object Model you will need to look at the VBA Docs on it:-

msdn.microsoft.com/.../ff837519.aspx

Unfortunately It is a large and complex API.

excel.if and word.if were files for using OO Vocabularies. We would advise against using them as they would be very out of date from any recent Word version. They allowed you to use a slightly different syntax. The code you supplied did not rely on a vocabulary so its best to leave commented out.

Regards

David


Prezados Amigos,

Usei este programa como exemplo para gerar documentos no Microsoft Word:

$set ooctrl( P) ooctrl( Q)
*copy "word.if". *> Word vocavularies
*copy "excel.if". *> Excel vocabularies
program-id. WORDAPI.
special-names. call-convention 2 is WinApi.

Class-Control.
*-------------

WordApp is class "$OLE$word.application". *> Word 97

Working-Storage Section.
*------------------------------
77 j pic 9(003).
77 k pic 9(003).
77 wChar pic X(001).

01 WordServer object reference value null.
01 theDocuments object reference value null.
01 theDocument object reference value null.
01 theSelection object reference value null.
01 theReplacement object reference value null.
01 theParagraphs object reference value null.
01 theParagraph object reference value null.
01 theRange object reference value null.
01 theFind object reference value null.

01 wText pic X(255).

01 found pic x comp-5.
88 found-True value 45.
88 found-False value 48.

01 Program-Flags pic 9(2) comp-5 value 1.
88 New-Instance value 1 false 0.

Linkage Section.
*----------------
01 wrdParam.
05 wrdOperation pic x(008).
05 wrdFileName pic x(255).
05 wrdText pic x(255).
05 wrdChange2 pic x(255).
05 wrdSearchStatus pic x(002).
05 wordVisible pic s9(001).
05 wordSaveMode pic s9(001).

Procedure Division Using wrdParam.
******************************************************************
*
* If New-Instance
* Perform New-Set-Instance
* End-if

Evaluate wrdOperation
When 'Create'
Perform Create-Aplication
When 'Open'
Perform File-Open
When 'Delete'
Perform Delete-Selection
When 'Insert'
Perform Insert-Text
When 'Find'
Perform Find-Text
When 'Replace'
Perform Replace-Text
When 'FReplace'
* Perform Find-and-Replace-Text
Perform Find-Text
Perform Replace-Text
When 'Preview'
Perform Print-Preview
When 'Print'
Perform Print-Document
When 'Quit'
Perform Quit-Set-Instance
End-Evaluate

Exit Program
.
*----------------------------------------------------------------
Create-Aplication Section.

*> Criar uma instancia do Word
Invoke wordapp "new" Returning wordServer

*> Pega o objeto de coleção Word documents
Invoke wordServer "getDocuments" Returning theDocuments

*> Seta se o Word será visualizado
invoke wordServer "SetVisible" using by value wordVisible
.
*----------------------------------------------------------------
File-Open Section.

*> Abre o arquivo em wrdFileName
Invoke theDocuments "Open" Using wrdFileName

*> Pega o documento ativo
Invoke wordServer "getActiveDocument" Returning theDocument
.
*----------------------------------------------------------------
Delete-Selection Section.

* invoke wordServer "getSelection" returning theSelection
* invoke theSelection "Delete"

*> Seleciona o texto encontrado
invoke theRange "select"

*> 'CUTila' o texto encontrado
invoke theRange "Cut"
.
*----------------------------------------------------------------
Insert-Text Section.

* Move wrdChange2 to wText

* Perform Null-Terminate-Routine
* Move wText to wrdChange2
* invoke wordServer "getSelection" returning theSelection
* invoke theSelection "InsertAfter" using by content wrdChange2

*> Insere o texto
invoke theRange "InsertAfter" using by content wrdChange2
.
*----------------------------------------------------------------
Find-Text Section.

Move "23" to wrdSearchStatus
Move wrdText to wText

Perform Null-Terminate-Routine

Move wText to wrdText

*> Pega o objeto Range
Invoke theDocument "getContent" returning theRange

*> Pega o objecto Find
Invoke theRange "getFind" returning theFind

*> A procura será para frente
Invoke theFind "setForward" using by value 1

*> A busca sera pelo conteudo de wrdText
Invoke theFind "setText" using by content wrdText

*> Procurar
Invoke theFind "execute"

*> Encontrou ?
Invoke theFind "getFound" returning found

*> Se encontrou...
if found-True
move "00" to wrdSearchStatus
end-if
.
*----------------------------------------------------------------
Find-and-Replace-Text Section.

Move "23" to wrdSearchStatus
Move wrdText to wText

Perform Null-Terminate-Routine

Move wText to wrdText
Move wrdChange2 to wText

Perform Null-Terminate-Routine

Move wText to wrdChange2

*> Pega o objeto Range
Invoke theDocument "getContent" returning theRange

*> Pega o objecto Find
Invoke theRange "getFind" Returning theFind

*> A procura será para frente
Invoke theFind "getReplacement" Returning theReplacement

Invoke theFind "setForward" Using by value 1
*> A busca sera pelo conteudo de wrdText

Invoke theFind "setText" Using by content wrdText
Invoke theReplacement "setText" Using by content wrdChange2

*> Procurar
* Invoke theFind "setReplace" Using by value 1
Invoke theFind "execute"

*> Encontrou ?
Invoke theFind "getFound" returning found

*> Se encontrou...
if found-True
move "00" to wrdSearchStatus
end-if
.
*----------------------------------------------------------------
Replace-Text Section.

Move wrdChange2 to wText

Perform Null-Terminate-Routine

Move wText to wrdChange2
subtract 01 from k

*> Seleciona o texto encontrado
invoke theRange "select"

*> Finalmente, muda o texto encontrado (wrdText)
*> para o desejado
invoke theRange "Cut"
move 00 to j
invoke theRange "InsertAfter" using " "
perform until j = k
add 01 to j
move wrdChange2(j:1) to wChar
invoke theRange "InsertAfter" using by content wChar
end-perform

*> Não preciso mais dos objetos Find e Range
Invoke theFind "finalize" returning theFind
Invoke theRange "finalize" returning theRange
.
*----------------------------------------------------------------
Print-Preview Section.

invoke theDocument "PrintPreview"
.
*----------------------------------------------------------------
Print-Document Section.

invoke theDocument "PrintOut" using by value 0
.
*----------------------------------------------------------------
New-Set-Instance Section.

set New-Instance to false
.
*----------------------------------------------------------------
Null-Terminate-Routine Section.

move length of wText to j

perform varying k from j by -1
until k = 0

if wText(k:1) not = spaces and not = X"00"
add 01 to k
move x"00" to wText(k:1)
exit section
end-if

end-perform

move x"00" to wText(j:1)
.
*----------------------------------------------------------------
Size-Of-String Section.

move length of wText to j

perform varying k from j by -1
until k = 0
or wtext(k:1) not = spaces and x"00"
end-perform
.
*----------------------------------------------------------------
Quit-Set-Instance Section.

*> Fechar o arquivo sem salvando-o
if wordSaveMode = 0
Invoke theDocument "Close" Using by value 0
else
if wordSaveMode = -1
Invoke theDocument "Close" Using by value -1
end-if
end-if

*> Finalizar o objecto de coleção Documents
Invoke theDocuments "finalize" Returning theDocuments

*> Tell Word to quit (it won't shut down otherwise)
Invoke wordServer "quit"

*> Finalizar o Word
Invoke wordServer "finalize" Returning wordServer
.

1 - Como descubro todos os métodos da classe wordapp ?

2 - Onde encontro o arquivo "word.if" , definido no inicio do programa ?

Atenciosamente

Rogerio Barbosa Ferreira

Eu estou construindo uma classe para facilitar o uso da WORD API

Ainda está precária, mas já tem as funções mais comuns.

Copy and enjoy.

#MSWordAPI


Prezados Amigos,

Usei este programa como exemplo para gerar documentos no Microsoft Word:

$set ooctrl( P) ooctrl( Q)
*copy "word.if". *> Word vocavularies
*copy "excel.if". *> Excel vocabularies
program-id. WORDAPI.
special-names. call-convention 2 is WinApi.

Class-Control.
*-------------

WordApp is class "$OLE$word.application". *> Word 97

Working-Storage Section.
*------------------------------
77 j pic 9(003).
77 k pic 9(003).
77 wChar pic X(001).

01 WordServer object reference value null.
01 theDocuments object reference value null.
01 theDocument object reference value null.
01 theSelection object reference value null.
01 theReplacement object reference value null.
01 theParagraphs object reference value null.
01 theParagraph object reference value null.
01 theRange object reference value null.
01 theFind object reference value null.

01 wText pic X(255).

01 found pic x comp-5.
88 found-True value 45.
88 found-False value 48.

01 Program-Flags pic 9(2) comp-5 value 1.
88 New-Instance value 1 false 0.

Linkage Section.
*----------------
01 wrdParam.
05 wrdOperation pic x(008).
05 wrdFileName pic x(255).
05 wrdText pic x(255).
05 wrdChange2 pic x(255).
05 wrdSearchStatus pic x(002).
05 wordVisible pic s9(001).
05 wordSaveMode pic s9(001).

Procedure Division Using wrdParam.
******************************************************************
*
* If New-Instance
* Perform New-Set-Instance
* End-if

Evaluate wrdOperation
When 'Create'
Perform Create-Aplication
When 'Open'
Perform File-Open
When 'Delete'
Perform Delete-Selection
When 'Insert'
Perform Insert-Text
When 'Find'
Perform Find-Text
When 'Replace'
Perform Replace-Text
When 'FReplace'
* Perform Find-and-Replace-Text
Perform Find-Text
Perform Replace-Text
When 'Preview'
Perform Print-Preview
When 'Print'
Perform Print-Document
When 'Quit'
Perform Quit-Set-Instance
End-Evaluate

Exit Program
.
*----------------------------------------------------------------
Create-Aplication Section.

*> Criar uma instancia do Word
Invoke wordapp "new" Returning wordServer

*> Pega o objeto de coleção Word documents
Invoke wordServer "getDocuments" Returning theDocuments

*> Seta se o Word será visualizado
invoke wordServer "SetVisible" using by value wordVisible
.
*----------------------------------------------------------------
File-Open Section.

*> Abre o arquivo em wrdFileName
Invoke theDocuments "Open" Using wrdFileName

*> Pega o documento ativo
Invoke wordServer "getActiveDocument" Returning theDocument
.
*----------------------------------------------------------------
Delete-Selection Section.

* invoke wordServer "getSelection" returning theSelection
* invoke theSelection "Delete"

*> Seleciona o texto encontrado
invoke theRange "select"

*> 'CUTila' o texto encontrado
invoke theRange "Cut"
.
*----------------------------------------------------------------
Insert-Text Section.

* Move wrdChange2 to wText

* Perform Null-Terminate-Routine
* Move wText to wrdChange2
* invoke wordServer "getSelection" returning theSelection
* invoke theSelection "InsertAfter" using by content wrdChange2

*> Insere o texto
invoke theRange "InsertAfter" using by content wrdChange2
.
*----------------------------------------------------------------
Find-Text Section.

Move "23" to wrdSearchStatus
Move wrdText to wText

Perform Null-Terminate-Routine

Move wText to wrdText

*> Pega o objeto Range
Invoke theDocument "getContent" returning theRange

*> Pega o objecto Find
Invoke theRange "getFind" returning theFind

*> A procura será para frente
Invoke theFind "setForward" using by value 1

*> A busca sera pelo conteudo de wrdText
Invoke theFind "setText" using by content wrdText

*> Procurar
Invoke theFind "execute"

*> Encontrou ?
Invoke theFind "getFound" returning found

*> Se encontrou...
if found-True
move "00" to wrdSearchStatus
end-if
.
*----------------------------------------------------------------
Find-and-Replace-Text Section.

Move "23" to wrdSearchStatus
Move wrdText to wText

Perform Null-Terminate-Routine

Move wText to wrdText
Move wrdChange2 to wText

Perform Null-Terminate-Routine

Move wText to wrdChange2

*> Pega o objeto Range
Invoke theDocument "getContent" returning theRange

*> Pega o objecto Find
Invoke theRange "getFind" Returning theFind

*> A procura será para frente
Invoke theFind "getReplacement" Returning theReplacement

Invoke theFind "setForward" Using by value 1
*> A busca sera pelo conteudo de wrdText

Invoke theFind "setText" Using by content wrdText
Invoke theReplacement "setText" Using by content wrdChange2

*> Procurar
* Invoke theFind "setReplace" Using by value 1
Invoke theFind "execute"

*> Encontrou ?
Invoke theFind "getFound" returning found

*> Se encontrou...
if found-True
move "00" to wrdSearchStatus
end-if
.
*----------------------------------------------------------------
Replace-Text Section.

Move wrdChange2 to wText

Perform Null-Terminate-Routine

Move wText to wrdChange2
subtract 01 from k

*> Seleciona o texto encontrado
invoke theRange "select"

*> Finalmente, muda o texto encontrado (wrdText)
*> para o desejado
invoke theRange "Cut"
move 00 to j
invoke theRange "InsertAfter" using " "
perform until j = k
add 01 to j
move wrdChange2(j:1) to wChar
invoke theRange "InsertAfter" using by content wChar
end-perform

*> Não preciso mais dos objetos Find e Range
Invoke theFind "finalize" returning theFind
Invoke theRange "finalize" returning theRange
.
*----------------------------------------------------------------
Print-Preview Section.

invoke theDocument "PrintPreview"
.
*----------------------------------------------------------------
Print-Document Section.

invoke theDocument "PrintOut" using by value 0
.
*----------------------------------------------------------------
New-Set-Instance Section.

set New-Instance to false
.
*----------------------------------------------------------------
Null-Terminate-Routine Section.

move length of wText to j

perform varying k from j by -1
until k = 0

if wText(k:1) not = spaces and not = X"00"
add 01 to k
move x"00" to wText(k:1)
exit section
end-if

end-perform

move x"00" to wText(j:1)
.
*----------------------------------------------------------------
Size-Of-String Section.

move length of wText to j

perform varying k from j by -1
until k = 0
or wtext(k:1) not = spaces and x"00"
end-perform
.
*----------------------------------------------------------------
Quit-Set-Instance Section.

*> Fechar o arquivo sem salvando-o
if wordSaveMode = 0
Invoke theDocument "Close" Using by value 0
else
if wordSaveMode = -1
Invoke theDocument "Close" Using by value -1
end-if
end-if

*> Finalizar o objecto de coleção Documents
Invoke theDocuments "finalize" Returning theDocuments

*> Tell Word to quit (it won't shut down otherwise)
Invoke wordServer "quit"

*> Finalizar o Word
Invoke wordServer "finalize" Returning wordServer
.

1 - Como descubro todos os métodos da classe wordapp ?

2 - Onde encontro o arquivo "word.if" , definido no inicio do programa ?

Atenciosamente

Rogerio Barbosa Ferreira

Is not possible attach a file?


Prezados Amigos,

Usei este programa como exemplo para gerar documentos no Microsoft Word:

$set ooctrl( P) ooctrl( Q)
*copy "word.if". *> Word vocavularies
*copy "excel.if". *> Excel vocabularies
program-id. WORDAPI.
special-names. call-convention 2 is WinApi.

Class-Control.
*-------------

WordApp is class "$OLE$word.application". *> Word 97

Working-Storage Section.
*------------------------------
77 j pic 9(003).
77 k pic 9(003).
77 wChar pic X(001).

01 WordServer object reference value null.
01 theDocuments object reference value null.
01 theDocument object reference value null.
01 theSelection object reference value null.
01 theReplacement object reference value null.
01 theParagraphs object reference value null.
01 theParagraph object reference value null.
01 theRange object reference value null.
01 theFind object reference value null.

01 wText pic X(255).

01 found pic x comp-5.
88 found-True value 45.
88 found-False value 48.

01 Program-Flags pic 9(2) comp-5 value 1.
88 New-Instance value 1 false 0.

Linkage Section.
*----------------
01 wrdParam.
05 wrdOperation pic x(008).
05 wrdFileName pic x(255).
05 wrdText pic x(255).
05 wrdChange2 pic x(255).
05 wrdSearchStatus pic x(002).
05 wordVisible pic s9(001).
05 wordSaveMode pic s9(001).

Procedure Division Using wrdParam.
******************************************************************
*
* If New-Instance
* Perform New-Set-Instance
* End-if

Evaluate wrdOperation
When 'Create'
Perform Create-Aplication
When 'Open'
Perform File-Open
When 'Delete'
Perform Delete-Selection
When 'Insert'
Perform Insert-Text
When 'Find'
Perform Find-Text
When 'Replace'
Perform Replace-Text
When 'FReplace'
* Perform Find-and-Replace-Text
Perform Find-Text
Perform Replace-Text
When 'Preview'
Perform Print-Preview
When 'Print'
Perform Print-Document
When 'Quit'
Perform Quit-Set-Instance
End-Evaluate

Exit Program
.
*----------------------------------------------------------------
Create-Aplication Section.

*> Criar uma instancia do Word
Invoke wordapp "new" Returning wordServer

*> Pega o objeto de coleção Word documents
Invoke wordServer "getDocuments" Returning theDocuments

*> Seta se o Word será visualizado
invoke wordServer "SetVisible" using by value wordVisible
.
*----------------------------------------------------------------
File-Open Section.

*> Abre o arquivo em wrdFileName
Invoke theDocuments "Open" Using wrdFileName

*> Pega o documento ativo
Invoke wordServer "getActiveDocument" Returning theDocument
.
*----------------------------------------------------------------
Delete-Selection Section.

* invoke wordServer "getSelection" returning theSelection
* invoke theSelection "Delete"

*> Seleciona o texto encontrado
invoke theRange "select"

*> 'CUTila' o texto encontrado
invoke theRange "Cut"
.
*----------------------------------------------------------------
Insert-Text Section.

* Move wrdChange2 to wText

* Perform Null-Terminate-Routine
* Move wText to wrdChange2
* invoke wordServer "getSelection" returning theSelection
* invoke theSelection "InsertAfter" using by content wrdChange2

*> Insere o texto
invoke theRange "InsertAfter" using by content wrdChange2
.
*----------------------------------------------------------------
Find-Text Section.

Move "23" to wrdSearchStatus
Move wrdText to wText

Perform Null-Terminate-Routine

Move wText to wrdText

*> Pega o objeto Range
Invoke theDocument "getContent" returning theRange

*> Pega o objecto Find
Invoke theRange "getFind" returning theFind

*> A procura será para frente
Invoke theFind "setForward" using by value 1

*> A busca sera pelo conteudo de wrdText
Invoke theFind "setText" using by content wrdText

*> Procurar
Invoke theFind "execute"

*> Encontrou ?
Invoke theFind "getFound" returning found

*> Se encontrou...
if found-True
move "00" to wrdSearchStatus
end-if
.
*----------------------------------------------------------------
Find-and-Replace-Text Section.

Move "23" to wrdSearchStatus
Move wrdText to wText

Perform Null-Terminate-Routine

Move wText to wrdText
Move wrdChange2 to wText

Perform Null-Terminate-Routine

Move wText to wrdChange2

*> Pega o objeto Range
Invoke theDocument "getContent" returning theRange

*> Pega o objecto Find
Invoke theRange "getFind" Returning theFind

*> A procura será para frente
Invoke theFind "getReplacement" Returning theReplacement

Invoke theFind "setForward" Using by value 1
*> A busca sera pelo conteudo de wrdText

Invoke theFind "setText" Using by content wrdText
Invoke theReplacement "setText" Using by content wrdChange2

*> Procurar
* Invoke theFind "setReplace" Using by value 1
Invoke theFind "execute"

*> Encontrou ?
Invoke theFind "getFound" returning found

*> Se encontrou...
if found-True
move "00" to wrdSearchStatus
end-if
.
*----------------------------------------------------------------
Replace-Text Section.

Move wrdChange2 to wText

Perform Null-Terminate-Routine

Move wText to wrdChange2
subtract 01 from k

*> Seleciona o texto encontrado
invoke theRange "select"

*> Finalmente, muda o texto encontrado (wrdText)
*> para o desejado
invoke theRange "Cut"
move 00 to j
invoke theRange "InsertAfter" using " "
perform until j = k
add 01 to j
move wrdChange2(j:1) to wChar
invoke theRange "InsertAfter" using by content wChar
end-perform

*> Não preciso mais dos objetos Find e Range
Invoke theFind "finalize" returning theFind
Invoke theRange "finalize" returning theRange
.
*----------------------------------------------------------------
Print-Preview Section.

invoke theDocument "PrintPreview"
.
*----------------------------------------------------------------
Print-Document Section.

invoke theDocument "PrintOut" using by value 0
.
*----------------------------------------------------------------
New-Set-Instance Section.

set New-Instance to false
.
*----------------------------------------------------------------
Null-Terminate-Routine Section.

move length of wText to j

perform varying k from j by -1
until k = 0

if wText(k:1) not = spaces and not = X"00"
add 01 to k
move x"00" to wText(k:1)
exit section
end-if

end-perform

move x"00" to wText(j:1)
.
*----------------------------------------------------------------
Size-Of-String Section.

move length of wText to j

perform varying k from j by -1
until k = 0
or wtext(k:1) not = spaces and x"00"
end-perform
.
*----------------------------------------------------------------
Quit-Set-Instance Section.

*> Fechar o arquivo sem salvando-o
if wordSaveMode = 0
Invoke theDocument "Close" Using by value 0
else
if wordSaveMode = -1
Invoke theDocument "Close" Using by value -1
end-if
end-if

*> Finalizar o objecto de coleção Documents
Invoke theDocuments "finalize" Returning theDocuments

*> Tell Word to quit (it won't shut down otherwise)
Invoke wordServer "quit"

*> Finalizar o Word
Invoke wordServer "finalize" Returning wordServer
.

1 - Como descubro todos os métodos da classe wordapp ?

2 - Onde encontro o arquivo "word.if" , definido no inicio do programa ?

Atenciosamente

Rogerio Barbosa Ferreira

Prezado Antonio,

Obrigado pela colaboração. Vou testar suas rotinas e te dou retorno em breve.

Vou te dizer o que estou fazendo.

Eu crio um documento no Word e onde tenho que inserir meus dados eu coloco um texto (&01, &02) e depois vou substituindo os mesmos pelos dados reais.

Me deparei com um problema onde tenho que inserir a foto de um determinado funcionário no documento.

No word é mole: inserir > image > e escolho a imagem que eu quero. Mas e em tempo de execução?

Você sabe quais são todos os métodos dessa classe do word?

Mais uma vez obrigado pela colaboração.

Atenciosamente

Rogerio Barbosa Ferreira

Rio de Janeiro - RJ - Brasil


Prezados Amigos,

Usei este programa como exemplo para gerar documentos no Microsoft Word:

$set ooctrl( P) ooctrl( Q)
*copy "word.if". *> Word vocavularies
*copy "excel.if". *> Excel vocabularies
program-id. WORDAPI.
special-names. call-convention 2 is WinApi.

Class-Control.
*-------------

WordApp is class "$OLE$word.application". *> Word 97

Working-Storage Section.
*------------------------------
77 j pic 9(003).
77 k pic 9(003).
77 wChar pic X(001).

01 WordServer object reference value null.
01 theDocuments object reference value null.
01 theDocument object reference value null.
01 theSelection object reference value null.
01 theReplacement object reference value null.
01 theParagraphs object reference value null.
01 theParagraph object reference value null.
01 theRange object reference value null.
01 theFind object reference value null.

01 wText pic X(255).

01 found pic x comp-5.
88 found-True value 45.
88 found-False value 48.

01 Program-Flags pic 9(2) comp-5 value 1.
88 New-Instance value 1 false 0.

Linkage Section.
*----------------
01 wrdParam.
05 wrdOperation pic x(008).
05 wrdFileName pic x(255).
05 wrdText pic x(255).
05 wrdChange2 pic x(255).
05 wrdSearchStatus pic x(002).
05 wordVisible pic s9(001).
05 wordSaveMode pic s9(001).

Procedure Division Using wrdParam.
******************************************************************
*
* If New-Instance
* Perform New-Set-Instance
* End-if

Evaluate wrdOperation
When 'Create'
Perform Create-Aplication
When 'Open'
Perform File-Open
When 'Delete'
Perform Delete-Selection
When 'Insert'
Perform Insert-Text
When 'Find'
Perform Find-Text
When 'Replace'
Perform Replace-Text
When 'FReplace'
* Perform Find-and-Replace-Text
Perform Find-Text
Perform Replace-Text
When 'Preview'
Perform Print-Preview
When 'Print'
Perform Print-Document
When 'Quit'
Perform Quit-Set-Instance
End-Evaluate

Exit Program
.
*----------------------------------------------------------------
Create-Aplication Section.

*> Criar uma instancia do Word
Invoke wordapp "new" Returning wordServer

*> Pega o objeto de coleção Word documents
Invoke wordServer "getDocuments" Returning theDocuments

*> Seta se o Word será visualizado
invoke wordServer "SetVisible" using by value wordVisible
.
*----------------------------------------------------------------
File-Open Section.

*> Abre o arquivo em wrdFileName
Invoke theDocuments "Open" Using wrdFileName

*> Pega o documento ativo
Invoke wordServer "getActiveDocument" Returning theDocument
.
*----------------------------------------------------------------
Delete-Selection Section.

* invoke wordServer "getSelection" returning theSelection
* invoke theSelection "Delete"

*> Seleciona o texto encontrado
invoke theRange "select"

*> 'CUTila' o texto encontrado
invoke theRange "Cut"
.
*----------------------------------------------------------------
Insert-Text Section.

* Move wrdChange2 to wText

* Perform Null-Terminate-Routine
* Move wText to wrdChange2
* invoke wordServer "getSelection" returning theSelection
* invoke theSelection "InsertAfter" using by content wrdChange2

*> Insere o texto
invoke theRange "InsertAfter" using by content wrdChange2
.
*----------------------------------------------------------------
Find-Text Section.

Move "23" to wrdSearchStatus
Move wrdText to wText

Perform Null-Terminate-Routine

Move wText to wrdText

*> Pega o objeto Range
Invoke theDocument "getContent" returning theRange

*> Pega o objecto Find
Invoke theRange "getFind" returning theFind

*> A procura será para frente
Invoke theFind "setForward" using by value 1

*> A busca sera pelo conteudo de wrdText
Invoke theFind "setText" using by content wrdText

*> Procurar
Invoke theFind "execute"

*> Encontrou ?
Invoke theFind "getFound" returning found

*> Se encontrou...
if found-True
move "00" to wrdSearchStatus
end-if
.
*----------------------------------------------------------------
Find-and-Replace-Text Section.

Move "23" to wrdSearchStatus
Move wrdText to wText

Perform Null-Terminate-Routine

Move wText to wrdText
Move wrdChange2 to wText

Perform Null-Terminate-Routine

Move wText to wrdChange2

*> Pega o objeto Range
Invoke theDocument "getContent" returning theRange

*> Pega o objecto Find
Invoke theRange "getFind" Returning theFind

*> A procura será para frente
Invoke theFind "getReplacement" Returning theReplacement

Invoke theFind "setForward" Using by value 1
*> A busca sera pelo conteudo de wrdText

Invoke theFind "setText" Using by content wrdText
Invoke theReplacement "setText" Using by content wrdChange2

*> Procurar
* Invoke theFind "setReplace" Using by value 1
Invoke theFind "execute"

*> Encontrou ?
Invoke theFind "getFound" returning found

*> Se encontrou...
if found-True
move "00" to wrdSearchStatus
end-if
.
*----------------------------------------------------------------
Replace-Text Section.

Move wrdChange2 to wText

Perform Null-Terminate-Routine

Move wText to wrdChange2
subtract 01 from k

*> Seleciona o texto encontrado
invoke theRange "select"

*> Finalmente, muda o texto encontrado (wrdText)
*> para o desejado
invoke theRange "Cut"
move 00 to j
invoke theRange "InsertAfter" using " "
perform until j = k
add 01 to j
move wrdChange2(j:1) to wChar
invoke theRange "InsertAfter" using by content wChar
end-perform

*> Não preciso mais dos objetos Find e Range
Invoke theFind "finalize" returning theFind
Invoke theRange "finalize" returning theRange
.
*----------------------------------------------------------------
Print-Preview Section.

invoke theDocument "PrintPreview"
.
*----------------------------------------------------------------
Print-Document Section.

invoke theDocument "PrintOut" using by value 0
.
*----------------------------------------------------------------
New-Set-Instance Section.

set New-Instance to false
.
*----------------------------------------------------------------
Null-Terminate-Routine Section.

move length of wText to j

perform varying k from j by -1
until k = 0

if wText(k:1) not = spaces and not = X"00"
add 01 to k
move x"00" to wText(k:1)
exit section
end-if

end-perform

move x"00" to wText(j:1)
.
*----------------------------------------------------------------
Size-Of-String Section.

move length of wText to j

perform varying k from j by -1
until k = 0
or wtext(k:1) not = spaces and x"00"
end-perform
.
*----------------------------------------------------------------
Quit-Set-Instance Section.

*> Fechar o arquivo sem salvando-o
if wordSaveMode = 0
Invoke theDocument "Close" Using by value 0
else
if wordSaveMode = -1
Invoke theDocument "Close" Using by value -1
end-if
end-if

*> Finalizar o objecto de coleção Documents
Invoke theDocuments "finalize" Returning theDocuments

*> Tell Word to quit (it won't shut down otherwise)
Invoke wordServer "quit"

*> Finalizar o Word
Invoke wordServer "finalize" Returning wordServer
.

1 - Como descubro todos os métodos da classe wordapp ?

2 - Onde encontro o arquivo "word.if" , definido no inicio do programa ?

Atenciosamente

Rogerio Barbosa Ferreira

Presado Antonio,

Eu ja tinha uma classe ajWrdWord dispolinilizada por voce, acho que nos exemplos e utilities aqui do suporte. Lembra dela?


Prezados Amigos,

Usei este programa como exemplo para gerar documentos no Microsoft Word:

$set ooctrl( P) ooctrl( Q)
*copy "word.if". *> Word vocavularies
*copy "excel.if". *> Excel vocabularies
program-id. WORDAPI.
special-names. call-convention 2 is WinApi.

Class-Control.
*-------------

WordApp is class "$OLE$word.application". *> Word 97

Working-Storage Section.
*------------------------------
77 j pic 9(003).
77 k pic 9(003).
77 wChar pic X(001).

01 WordServer object reference value null.
01 theDocuments object reference value null.
01 theDocument object reference value null.
01 theSelection object reference value null.
01 theReplacement object reference value null.
01 theParagraphs object reference value null.
01 theParagraph object reference value null.
01 theRange object reference value null.
01 theFind object reference value null.

01 wText pic X(255).

01 found pic x comp-5.
88 found-True value 45.
88 found-False value 48.

01 Program-Flags pic 9(2) comp-5 value 1.
88 New-Instance value 1 false 0.

Linkage Section.
*----------------
01 wrdParam.
05 wrdOperation pic x(008).
05 wrdFileName pic x(255).
05 wrdText pic x(255).
05 wrdChange2 pic x(255).
05 wrdSearchStatus pic x(002).
05 wordVisible pic s9(001).
05 wordSaveMode pic s9(001).

Procedure Division Using wrdParam.
******************************************************************
*
* If New-Instance
* Perform New-Set-Instance
* End-if

Evaluate wrdOperation
When 'Create'
Perform Create-Aplication
When 'Open'
Perform File-Open
When 'Delete'
Perform Delete-Selection
When 'Insert'
Perform Insert-Text
When 'Find'
Perform Find-Text
When 'Replace'
Perform Replace-Text
When 'FReplace'
* Perform Find-and-Replace-Text
Perform Find-Text
Perform Replace-Text
When 'Preview'
Perform Print-Preview
When 'Print'
Perform Print-Document
When 'Quit'
Perform Quit-Set-Instance
End-Evaluate

Exit Program
.
*----------------------------------------------------------------
Create-Aplication Section.

*> Criar uma instancia do Word
Invoke wordapp "new" Returning wordServer

*> Pega o objeto de coleção Word documents
Invoke wordServer "getDocuments" Returning theDocuments

*> Seta se o Word será visualizado
invoke wordServer "SetVisible" using by value wordVisible
.
*----------------------------------------------------------------
File-Open Section.

*> Abre o arquivo em wrdFileName
Invoke theDocuments "Open" Using wrdFileName

*> Pega o documento ativo
Invoke wordServer "getActiveDocument" Returning theDocument
.
*----------------------------------------------------------------
Delete-Selection Section.

* invoke wordServer "getSelection" returning theSelection
* invoke theSelection "Delete"

*> Seleciona o texto encontrado
invoke theRange "select"

*> 'CUTila' o texto encontrado
invoke theRange "Cut"
.
*----------------------------------------------------------------
Insert-Text Section.

* Move wrdChange2 to wText

* Perform Null-Terminate-Routine
* Move wText to wrdChange2
* invoke wordServer "getSelection" returning theSelection
* invoke theSelection "InsertAfter" using by content wrdChange2

*> Insere o texto
invoke theRange "InsertAfter" using by content wrdChange2
.
*----------------------------------------------------------------
Find-Text Section.

Move "23" to wrdSearchStatus
Move wrdText to wText

Perform Null-Terminate-Routine

Move wText to wrdText

*> Pega o objeto Range
Invoke theDocument "getContent" returning theRange

*> Pega o objecto Find
Invoke theRange "getFind" returning theFind

*> A procura será para frente
Invoke theFind "setForward" using by value 1

*> A busca sera pelo conteudo de wrdText
Invoke theFind "setText" using by content wrdText

*> Procurar
Invoke theFind "execute"

*> Encontrou ?
Invoke theFind "getFound" returning found

*> Se encontrou...
if found-True
move "00" to wrdSearchStatus
end-if
.
*----------------------------------------------------------------
Find-and-Replace-Text Section.

Move "23" to wrdSearchStatus
Move wrdText to wText

Perform Null-Terminate-Routine

Move wText to wrdText
Move wrdChange2 to wText

Perform Null-Terminate-Routine

Move wText to wrdChange2

*> Pega o objeto Range
Invoke theDocument "getContent" returning theRange

*> Pega o objecto Find
Invoke theRange "getFind" Returning theFind

*> A procura será para frente
Invoke theFind "getReplacement" Returning theReplacement

Invoke theFind "setForward" Using by value 1
*> A busca sera pelo conteudo de wrdText

Invoke theFind "setText" Using by content wrdText
Invoke theReplacement "setText" Using by content wrdChange2

*> Procurar
* Invoke theFind "setReplace" Using by value 1
Invoke theFind "execute"

*> Encontrou ?
Invoke theFind "getFound" returning found

*> Se encontrou...
if found-True
move "00" to wrdSearchStatus
end-if
.
*----------------------------------------------------------------
Replace-Text Section.

Move wrdChange2 to wText

Perform Null-Terminate-Routine

Move wText to wrdChange2
subtract 01 from k

*> Seleciona o texto encontrado
invoke theRange "select"

*> Finalmente, muda o texto encontrado (wrdText)
*> para o desejado
invoke theRange "Cut"
move 00 to j
invoke theRange "InsertAfter" using " "
perform until j = k
add 01 to j
move wrdChange2(j:1) to wChar
invoke theRange "InsertAfter" using by content wChar
end-perform

*> Não preciso mais dos objetos Find e Range
Invoke theFind "finalize" returning theFind
Invoke theRange "finalize" returning theRange
.
*----------------------------------------------------------------
Print-Preview Section.

invoke theDocument "PrintPreview"
.
*----------------------------------------------------------------
Print-Document Section.

invoke theDocument "PrintOut" using by value 0
.
*----------------------------------------------------------------
New-Set-Instance Section.

set New-Instance to false
.
*----------------------------------------------------------------
Null-Terminate-Routine Section.

move length of wText to j

perform varying k from j by -1
until k = 0

if wText(k:1) not = spaces and not = X"00"
add 01 to k
move x"00" to wText(k:1)
exit section
end-if

end-perform

move x"00" to wText(j:1)
.
*----------------------------------------------------------------
Size-Of-String Section.

move length of wText to j

perform varying k from j by -1
until k = 0
or wtext(k:1) not = spaces and x"00"
end-perform
.
*----------------------------------------------------------------
Quit-Set-Instance Section.

*> Fechar o arquivo sem salvando-o
if wordSaveMode = 0
Invoke theDocument "Close" Using by value 0
else
if wordSaveMode = -1
Invoke theDocument "Close" Using by value -1
end-if
end-if

*> Finalizar o objecto de coleção Documents
Invoke theDocuments "finalize" Returning theDocuments

*> Tell Word to quit (it won't shut down otherwise)
Invoke wordServer "quit"

*> Finalizar o Word
Invoke wordServer "finalize" Returning wordServer
.

1 - Como descubro todos os métodos da classe wordapp ?

2 - Onde encontro o arquivo "word.if" , definido no inicio do programa ?

Atenciosamente

Rogerio Barbosa Ferreira

Olá Rogério.

Cara, eu não me lembrava disso.

Esse programa é procedural, depois que eu conheci a tal da OOP, eu não me vicie.

Eu comecei a construir essa classe, o problema é que agora eu não desenvolvo mais profissionalmente (agora trabalho como prestação de conta em um prefeitura), então, faço isso em horas vagas.

Eu procurei na internet por "word api inserir imagem vba" e de cara encontrei isto aqui: https://goo.gl/qVW4rp

Sub InserirImagem()

   Selection.InlineShapes.AddPicture "d:\\image.png"

End Sub

Vi que a inserção é feita no objeto InLineShapes, que é obtido em Selection.

Então testei pegando o "Selection" da "Application" e PIMBÁ!.

Eu ainda não sei como inserir uma imagem em uma determinada posição, este método insere na posição atual do cursor.

Copie este método na classe que te passei.

      *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*

     *                                                                 *

     *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*

      Method-id. "AddPicture".

     *------------------------------

      Local-storage          Section.

     *------------------------------

      77           InlineShapes        Object Reference.

      77           WrdPic              Object Reference.

     *------------------------------

      Linkage                Section.

     *------------------------------

      77           lnkLineShape        Object Reference.

      77           lnkLinkToFile       PIC S9(009) COMP-5. *> [IN][OPTIONAL]

      77           lnkSaveWithDocument PIC S9(009) COMP-5. *> [IN][OPTIONAL]

      77           lnkRange-CBL        PIC S9(009) COMP-5. *> [IN][OPTIONAL]

      77           lnkFileName         PIC  X(256).

     *******************************************************************

      Procedure              Division  Using lnkFileName

                                             lnkLinkToFile

                                             lnkSaveWithDocument

                                             lnkRange-CBL

                                   Returning lnkLineShape.

     *******************************************************************

       *> Pega o objeto Selection da Application

          Invoke   wordServer "getSelection" Returning theSelection

       *> Pega o objeto InlineShapes da Selection

          Invoke  theSelection "getInlineShapes" Returning InlineShapes

       *> Adicionar a imagem e retornar um objeto InlineShape

          Invoke   InlineShapes "AddPicture" Using lnkFileName

                                         Returning WrdPic

          If       Address of lnkLineShape is not equal null

                   set lnkLineShape    to WrdPic

          End-If

          Exit     Method

          .

      End method "AddPicture".

Para usar o método:

          Invoke   WRDAPP "AddPicture" Using z"C:\\Fotos\\FotoDoJuca.jpg"

                                                            Returning umaImagem

WRDAPP é uma instância da classe CBLWRDAPI.

"umaImagem" é uma "Object Reference" para você a utilizar, caso você queira redimensionar a imagem.

Like this:

          Invoke   umObjeto "setScaleHeight" Using By Value 50

          Invoke   umObjeto "setScaleWidth"  Using By Value 30

Ou:

          Invoke   umObjeto "setHeight" Using By Value 50

          Invoke   umObjeto "setWidth"  Using By Value 30

O jeito é buscar na web por exemplos, de preferência em VB.

Outro macete é executar no word a ação que desejar gravando-a em um macro, depois é editar a macro para ter uma ideia de como a coisa acontece.


#InsertImage
#MSWordAPI

Prezados Amigos,

Usei este programa como exemplo para gerar documentos no Microsoft Word:

$set ooctrl( P) ooctrl( Q)
*copy "word.if". *> Word vocavularies
*copy "excel.if". *> Excel vocabularies
program-id. WORDAPI.
special-names. call-convention 2 is WinApi.

Class-Control.
*-------------

WordApp is class "$OLE$word.application". *> Word 97

Working-Storage Section.
*------------------------------
77 j pic 9(003).
77 k pic 9(003).
77 wChar pic X(001).

01 WordServer object reference value null.
01 theDocuments object reference value null.
01 theDocument object reference value null.
01 theSelection object reference value null.
01 theReplacement object reference value null.
01 theParagraphs object reference value null.
01 theParagraph object reference value null.
01 theRange object reference value null.
01 theFind object reference value null.

01 wText pic X(255).

01 found pic x comp-5.
88 found-True value 45.
88 found-False value 48.

01 Program-Flags pic 9(2) comp-5 value 1.
88 New-Instance value 1 false 0.

Linkage Section.
*----------------
01 wrdParam.
05 wrdOperation pic x(008).
05 wrdFileName pic x(255).
05 wrdText pic x(255).
05 wrdChange2 pic x(255).
05 wrdSearchStatus pic x(002).
05 wordVisible pic s9(001).
05 wordSaveMode pic s9(001).

Procedure Division Using wrdParam.
******************************************************************
*
* If New-Instance
* Perform New-Set-Instance
* End-if

Evaluate wrdOperation
When 'Create'
Perform Create-Aplication
When 'Open'
Perform File-Open
When 'Delete'
Perform Delete-Selection
When 'Insert'
Perform Insert-Text
When 'Find'
Perform Find-Text
When 'Replace'
Perform Replace-Text
When 'FReplace'
* Perform Find-and-Replace-Text
Perform Find-Text
Perform Replace-Text
When 'Preview'
Perform Print-Preview
When 'Print'
Perform Print-Document
When 'Quit'
Perform Quit-Set-Instance
End-Evaluate

Exit Program
.
*----------------------------------------------------------------
Create-Aplication Section.

*> Criar uma instancia do Word
Invoke wordapp "new" Returning wordServer

*> Pega o objeto de coleção Word documents
Invoke wordServer "getDocuments" Returning theDocuments

*> Seta se o Word será visualizado
invoke wordServer "SetVisible" using by value wordVisible
.
*----------------------------------------------------------------
File-Open Section.

*> Abre o arquivo em wrdFileName
Invoke theDocuments "Open" Using wrdFileName

*> Pega o documento ativo
Invoke wordServer "getActiveDocument" Returning theDocument
.
*----------------------------------------------------------------
Delete-Selection Section.

* invoke wordServer "getSelection" returning theSelection
* invoke theSelection "Delete"

*> Seleciona o texto encontrado
invoke theRange "select"

*> 'CUTila' o texto encontrado
invoke theRange "Cut"
.
*----------------------------------------------------------------
Insert-Text Section.

* Move wrdChange2 to wText

* Perform Null-Terminate-Routine
* Move wText to wrdChange2
* invoke wordServer "getSelection" returning theSelection
* invoke theSelection "InsertAfter" using by content wrdChange2

*> Insere o texto
invoke theRange "InsertAfter" using by content wrdChange2
.
*----------------------------------------------------------------
Find-Text Section.

Move "23" to wrdSearchStatus
Move wrdText to wText

Perform Null-Terminate-Routine

Move wText to wrdText

*> Pega o objeto Range
Invoke theDocument "getContent" returning theRange

*> Pega o objecto Find
Invoke theRange "getFind" returning theFind

*> A procura será para frente
Invoke theFind "setForward" using by value 1

*> A busca sera pelo conteudo de wrdText
Invoke theFind "setText" using by content wrdText

*> Procurar
Invoke theFind "execute"

*> Encontrou ?
Invoke theFind "getFound" returning found

*> Se encontrou...
if found-True
move "00" to wrdSearchStatus
end-if
.
*----------------------------------------------------------------
Find-and-Replace-Text Section.

Move "23" to wrdSearchStatus
Move wrdText to wText

Perform Null-Terminate-Routine

Move wText to wrdText
Move wrdChange2 to wText

Perform Null-Terminate-Routine

Move wText to wrdChange2

*> Pega o objeto Range
Invoke theDocument "getContent" returning theRange

*> Pega o objecto Find
Invoke theRange "getFind" Returning theFind

*> A procura será para frente
Invoke theFind "getReplacement" Returning theReplacement

Invoke theFind "setForward" Using by value 1
*> A busca sera pelo conteudo de wrdText

Invoke theFind "setText" Using by content wrdText
Invoke theReplacement "setText" Using by content wrdChange2

*> Procurar
* Invoke theFind "setReplace" Using by value 1
Invoke theFind "execute"

*> Encontrou ?
Invoke theFind "getFound" returning found

*> Se encontrou...
if found-True
move "00" to wrdSearchStatus
end-if
.
*----------------------------------------------------------------
Replace-Text Section.

Move wrdChange2 to wText

Perform Null-Terminate-Routine

Move wText to wrdChange2
subtract 01 from k

*> Seleciona o texto encontrado
invoke theRange "select"

*> Finalmente, muda o texto encontrado (wrdText)
*> para o desejado
invoke theRange "Cut"
move 00 to j
invoke theRange "InsertAfter" using " "
perform until j = k
add 01 to j
move wrdChange2(j:1) to wChar
invoke theRange "InsertAfter" using by content wChar
end-perform

*> Não preciso mais dos objetos Find e Range
Invoke theFind "finalize" returning theFind
Invoke theRange "finalize" returning theRange
.
*----------------------------------------------------------------
Print-Preview Section.

invoke theDocument "PrintPreview"
.
*----------------------------------------------------------------
Print-Document Section.

invoke theDocument "PrintOut" using by value 0
.
*----------------------------------------------------------------
New-Set-Instance Section.

set New-Instance to false
.
*----------------------------------------------------------------
Null-Terminate-Routine Section.

move length of wText to j

perform varying k from j by -1
until k = 0

if wText(k:1) not = spaces and not = X"00"
add 01 to k
move x"00" to wText(k:1)
exit section
end-if

end-perform

move x"00" to wText(j:1)
.
*----------------------------------------------------------------
Size-Of-String Section.

move length of wText to j

perform varying k from j by -1
until k = 0
or wtext(k:1) not = spaces and x"00"
end-perform
.
*----------------------------------------------------------------
Quit-Set-Instance Section.

*> Fechar o arquivo sem salvando-o
if wordSaveMode = 0
Invoke theDocument "Close" Using by value 0
else
if wordSaveMode = -1
Invoke theDocument "Close" Using by value -1
end-if
end-if

*> Finalizar o objecto de coleção Documents
Invoke theDocuments "finalize" Returning theDocuments

*> Tell Word to quit (it won't shut down otherwise)
Invoke wordServer "quit"

*> Finalizar o Word
Invoke wordServer "finalize" Returning wordServer
.

1 - Como descubro todos os métodos da classe wordapp ?

2 - Onde encontro o arquivo "word.if" , definido no inicio do programa ?

Atenciosamente

Rogerio Barbosa Ferreira

Antonio, desculpe pela demora

mas é que tive que atender a outras prioridades e esse projeto ficou parada. Agradeço a ajuda e vou testar assim que puder.

Rogerio Barbosa

Rio de Janeiro


Prezados Amigos,

Usei este programa como exemplo para gerar documentos no Microsoft Word:

$set ooctrl( P) ooctrl( Q)
*copy "word.if". *> Word vocavularies
*copy "excel.if". *> Excel vocabularies
program-id. WORDAPI.
special-names. call-convention 2 is WinApi.

Class-Control.
*-------------

WordApp is class "$OLE$word.application". *> Word 97

Working-Storage Section.
*------------------------------
77 j pic 9(003).
77 k pic 9(003).
77 wChar pic X(001).

01 WordServer object reference value null.
01 theDocuments object reference value null.
01 theDocument object reference value null.
01 theSelection object reference value null.
01 theReplacement object reference value null.
01 theParagraphs object reference value null.
01 theParagraph object reference value null.
01 theRange object reference value null.
01 theFind object reference value null.

01 wText pic X(255).

01 found pic x comp-5.
88 found-True value 45.
88 found-False value 48.

01 Program-Flags pic 9(2) comp-5 value 1.
88 New-Instance value 1 false 0.

Linkage Section.
*----------------
01 wrdParam.
05 wrdOperation pic x(008).
05 wrdFileName pic x(255).
05 wrdText pic x(255).
05 wrdChange2 pic x(255).
05 wrdSearchStatus pic x(002).
05 wordVisible pic s9(001).
05 wordSaveMode pic s9(001).

Procedure Division Using wrdParam.
******************************************************************
*
* If New-Instance
* Perform New-Set-Instance
* End-if

Evaluate wrdOperation
When 'Create'
Perform Create-Aplication
When 'Open'
Perform File-Open
When 'Delete'
Perform Delete-Selection
When 'Insert'
Perform Insert-Text
When 'Find'
Perform Find-Text
When 'Replace'
Perform Replace-Text
When 'FReplace'
* Perform Find-and-Replace-Text
Perform Find-Text
Perform Replace-Text
When 'Preview'
Perform Print-Preview
When 'Print'
Perform Print-Document
When 'Quit'
Perform Quit-Set-Instance
End-Evaluate

Exit Program
.
*----------------------------------------------------------------
Create-Aplication Section.

*> Criar uma instancia do Word
Invoke wordapp "new" Returning wordServer

*> Pega o objeto de coleção Word documents
Invoke wordServer "getDocuments" Returning theDocuments

*> Seta se o Word será visualizado
invoke wordServer "SetVisible" using by value wordVisible
.
*----------------------------------------------------------------
File-Open Section.

*> Abre o arquivo em wrdFileName
Invoke theDocuments "Open" Using wrdFileName

*> Pega o documento ativo
Invoke wordServer "getActiveDocument" Returning theDocument
.
*----------------------------------------------------------------
Delete-Selection Section.

* invoke wordServer "getSelection" returning theSelection
* invoke theSelection "Delete"

*> Seleciona o texto encontrado
invoke theRange "select"

*> 'CUTila' o texto encontrado
invoke theRange "Cut"
.
*----------------------------------------------------------------
Insert-Text Section.

* Move wrdChange2 to wText

* Perform Null-Terminate-Routine
* Move wText to wrdChange2
* invoke wordServer "getSelection" returning theSelection
* invoke theSelection "InsertAfter" using by content wrdChange2

*> Insere o texto
invoke theRange "InsertAfter" using by content wrdChange2
.
*----------------------------------------------------------------
Find-Text Section.

Move "23" to wrdSearchStatus
Move wrdText to wText

Perform Null-Terminate-Routine

Move wText to wrdText

*> Pega o objeto Range
Invoke theDocument "getContent" returning theRange

*> Pega o objecto Find
Invoke theRange "getFind" returning theFind

*> A procura será para frente
Invoke theFind "setForward" using by value 1

*> A busca sera pelo conteudo de wrdText
Invoke theFind "setText" using by content wrdText

*> Procurar
Invoke theFind "execute"

*> Encontrou ?
Invoke theFind "getFound" returning found

*> Se encontrou...
if found-True
move "00" to wrdSearchStatus
end-if
.
*----------------------------------------------------------------
Find-and-Replace-Text Section.

Move "23" to wrdSearchStatus
Move wrdText to wText

Perform Null-Terminate-Routine

Move wText to wrdText
Move wrdChange2 to wText

Perform Null-Terminate-Routine

Move wText to wrdChange2

*> Pega o objeto Range
Invoke theDocument "getContent" returning theRange

*> Pega o objecto Find
Invoke theRange "getFind" Returning theFind

*> A procura será para frente
Invoke theFind "getReplacement" Returning theReplacement

Invoke theFind "setForward" Using by value 1
*> A busca sera pelo conteudo de wrdText

Invoke theFind "setText" Using by content wrdText
Invoke theReplacement "setText" Using by content wrdChange2

*> Procurar
* Invoke theFind "setReplace" Using by value 1
Invoke theFind "execute"

*> Encontrou ?
Invoke theFind "getFound" returning found

*> Se encontrou...
if found-True
move "00" to wrdSearchStatus
end-if
.
*----------------------------------------------------------------
Replace-Text Section.

Move wrdChange2 to wText

Perform Null-Terminate-Routine

Move wText to wrdChange2
subtract 01 from k

*> Seleciona o texto encontrado
invoke theRange "select"

*> Finalmente, muda o texto encontrado (wrdText)
*> para o desejado
invoke theRange "Cut"
move 00 to j
invoke theRange "InsertAfter" using " "
perform until j = k
add 01 to j
move wrdChange2(j:1) to wChar
invoke theRange "InsertAfter" using by content wChar
end-perform

*> Não preciso mais dos objetos Find e Range
Invoke theFind "finalize" returning theFind
Invoke theRange "finalize" returning theRange
.
*----------------------------------------------------------------
Print-Preview Section.

invoke theDocument "PrintPreview"
.
*----------------------------------------------------------------
Print-Document Section.

invoke theDocument "PrintOut" using by value 0
.
*----------------------------------------------------------------
New-Set-Instance Section.

set New-Instance to false
.
*----------------------------------------------------------------
Null-Terminate-Routine Section.

move length of wText to j

perform varying k from j by -1
until k = 0

if wText(k:1) not = spaces and not = X"00"
add 01 to k
move x"00" to wText(k:1)
exit section
end-if

end-perform

move x"00" to wText(j:1)
.
*----------------------------------------------------------------
Size-Of-String Section.

move length of wText to j

perform varying k from j by -1
until k = 0
or wtext(k:1) not = spaces and x"00"
end-perform
.
*----------------------------------------------------------------
Quit-Set-Instance Section.

*> Fechar o arquivo sem salvando-o
if wordSaveMode = 0
Invoke theDocument "Close" Using by value 0
else
if wordSaveMode = -1
Invoke theDocument "Close" Using by value -1
end-if
end-if

*> Finalizar o objecto de coleção Documents
Invoke theDocuments "finalize" Returning theDocuments

*> Tell Word to quit (it won't shut down otherwise)
Invoke wordServer "quit"

*> Finalizar o Word
Invoke wordServer "finalize" Returning wordServer
.

1 - Como descubro todos os métodos da classe wordapp ?

2 - Onde encontro o arquivo "word.if" , definido no inicio do programa ?

Atenciosamente

Rogerio Barbosa Ferreira

Pessoal, montei uma rotina que trabalha com o WORD 2010 seguindo o post de vocês , esta funcional, porem tenho no meu documento um cabeçalho preciso deixar ele ativo para alterar campos nele e fechado não estou conseguindo montar os objetos para isso, se alguém tiver um exemplo agradeço muito

Prezados Amigos,

Usei este programa como exemplo para gerar documentos no Microsoft Word:

$set ooctrl( P) ooctrl( Q)
*copy "word.if". *> Word vocavularies
*copy "excel.if". *> Excel vocabularies
program-id. WORDAPI.
special-names. call-convention 2 is WinApi.

Class-Control.
*-------------

WordApp is class "$OLE$word.application". *> Word 97

Working-Storage Section.
*------------------------------
77 j pic 9(003).
77 k pic 9(003).
77 wChar pic X(001).

01 WordServer object reference value null.
01 theDocuments object reference value null.
01 theDocument object reference value null.
01 theSelection object reference value null.
01 theReplacement object reference value null.
01 theParagraphs object reference value null.
01 theParagraph object reference value null.
01 theRange object reference value null.
01 theFind object reference value null.

01 wText pic X(255).

01 found pic x comp-5.
88 found-True value 45.
88 found-False value 48.

01 Program-Flags pic 9(2) comp-5 value 1.
88 New-Instance value 1 false 0.

Linkage Section.
*----------------
01 wrdParam.
05 wrdOperation pic x(008).
05 wrdFileName pic x(255).
05 wrdText pic x(255).
05 wrdChange2 pic x(255).
05 wrdSearchStatus pic x(002).
05 wordVisible pic s9(001).
05 wordSaveMode pic s9(001).

Procedure Division Using wrdParam.
******************************************************************
*
* If New-Instance
* Perform New-Set-Instance
* End-if

Evaluate wrdOperation
When 'Create'
Perform Create-Aplication
When 'Open'
Perform File-Open
When 'Delete'
Perform Delete-Selection
When 'Insert'
Perform Insert-Text
When 'Find'
Perform Find-Text
When 'Replace'
Perform Replace-Text
When 'FReplace'
* Perform Find-and-Replace-Text
Perform Find-Text
Perform Replace-Text
When 'Preview'
Perform Print-Preview
When 'Print'
Perform Print-Document
When 'Quit'
Perform Quit-Set-Instance
End-Evaluate

Exit Program
.
*----------------------------------------------------------------
Create-Aplication Section.

*> Criar uma instancia do Word
Invoke wordapp "new" Returning wordServer

*> Pega o objeto de coleção Word documents
Invoke wordServer "getDocuments" Returning theDocuments

*> Seta se o Word será visualizado
invoke wordServer "SetVisible" using by value wordVisible
.
*----------------------------------------------------------------
File-Open Section.

*> Abre o arquivo em wrdFileName
Invoke theDocuments "Open" Using wrdFileName

*> Pega o documento ativo
Invoke wordServer "getActiveDocument" Returning theDocument
.
*----------------------------------------------------------------
Delete-Selection Section.

* invoke wordServer "getSelection" returning theSelection
* invoke theSelection "Delete"

*> Seleciona o texto encontrado
invoke theRange "select"

*> 'CUTila' o texto encontrado
invoke theRange "Cut"
.
*----------------------------------------------------------------
Insert-Text Section.

* Move wrdChange2 to wText

* Perform Null-Terminate-Routine
* Move wText to wrdChange2
* invoke wordServer "getSelection" returning theSelection
* invoke theSelection "InsertAfter" using by content wrdChange2

*> Insere o texto
invoke theRange "InsertAfter" using by content wrdChange2
.
*----------------------------------------------------------------
Find-Text Section.

Move "23" to wrdSearchStatus
Move wrdText to wText

Perform Null-Terminate-Routine

Move wText to wrdText

*> Pega o objeto Range
Invoke theDocument "getContent" returning theRange

*> Pega o objecto Find
Invoke theRange "getFind" returning theFind

*> A procura será para frente
Invoke theFind "setForward" using by value 1

*> A busca sera pelo conteudo de wrdText
Invoke theFind "setText" using by content wrdText

*> Procurar
Invoke theFind "execute"

*> Encontrou ?
Invoke theFind "getFound" returning found

*> Se encontrou...
if found-True
move "00" to wrdSearchStatus
end-if
.
*----------------------------------------------------------------
Find-and-Replace-Text Section.

Move "23" to wrdSearchStatus
Move wrdText to wText

Perform Null-Terminate-Routine

Move wText to wrdText
Move wrdChange2 to wText

Perform Null-Terminate-Routine

Move wText to wrdChange2

*> Pega o objeto Range
Invoke theDocument "getContent" returning theRange

*> Pega o objecto Find
Invoke theRange "getFind" Returning theFind

*> A procura será para frente
Invoke theFind "getReplacement" Returning theReplacement

Invoke theFind "setForward" Using by value 1
*> A busca sera pelo conteudo de wrdText

Invoke theFind "setText" Using by content wrdText
Invoke theReplacement "setText" Using by content wrdChange2

*> Procurar
* Invoke theFind "setReplace" Using by value 1
Invoke theFind "execute"

*> Encontrou ?
Invoke theFind "getFound" returning found

*> Se encontrou...
if found-True
move "00" to wrdSearchStatus
end-if
.
*----------------------------------------------------------------
Replace-Text Section.

Move wrdChange2 to wText

Perform Null-Terminate-Routine

Move wText to wrdChange2
subtract 01 from k

*> Seleciona o texto encontrado
invoke theRange "select"

*> Finalmente, muda o texto encontrado (wrdText)
*> para o desejado
invoke theRange "Cut"
move 00 to j
invoke theRange "InsertAfter" using " "
perform until j = k
add 01 to j
move wrdChange2(j:1) to wChar
invoke theRange "InsertAfter" using by content wChar
end-perform

*> Não preciso mais dos objetos Find e Range
Invoke theFind "finalize" returning theFind
Invoke theRange "finalize" returning theRange
.
*----------------------------------------------------------------
Print-Preview Section.

invoke theDocument "PrintPreview"
.
*----------------------------------------------------------------
Print-Document Section.

invoke theDocument "PrintOut" using by value 0
.
*----------------------------------------------------------------
New-Set-Instance Section.

set New-Instance to false
.
*----------------------------------------------------------------
Null-Terminate-Routine Section.

move length of wText to j

perform varying k from j by -1
until k = 0

if wText(k:1) not = spaces and not = X"00"
add 01 to k
move x"00" to wText(k:1)
exit section
end-if

end-perform

move x"00" to wText(j:1)
.
*----------------------------------------------------------------
Size-Of-String Section.

move length of wText to j

perform varying k from j by -1
until k = 0
or wtext(k:1) not = spaces and x"00"
end-perform
.
*----------------------------------------------------------------
Quit-Set-Instance Section.

*> Fechar o arquivo sem salvando-o
if wordSaveMode = 0
Invoke theDocument "Close" Using by value 0
else
if wordSaveMode = -1
Invoke theDocument "Close" Using by value -1
end-if
end-if

*> Finalizar o objecto de coleção Documents
Invoke theDocuments "finalize" Returning theDocuments

*> Tell Word to quit (it won't shut down otherwise)
Invoke wordServer "quit"

*> Finalizar o Word
Invoke wordServer "finalize" Returning wordServer
.

1 - Como descubro todos os métodos da classe wordapp ?

2 - Onde encontro o arquivo "word.if" , definido no inicio do programa ?

Atenciosamente

Rogerio Barbosa Ferreira

Prezado Paulo,

Não tem como colocar esse cabeçalho como texto do documento e aí, alterar os campos que vc precisa?