Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Word Bookmarks and Multiple Letters
Message
De
19/07/2005 09:00:19
Bill Drew
Independent Consultant
Chicago, Illinois, États-Unis
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Titre:
Word Bookmarks and Multiple Letters
Versions des environnements
Visual FoxPro:
VFP 7
OS:
Windows XP
Database:
Visual FoxPro
Divers
Thread ID:
01033797
Message ID:
01033797
Vues:
57
I have run into a timing problem when automating word. I assume that there is a way around it but could use some hints. (I got the bookmark technique here from Tamar Granor.)

The program below won't print more that 20 or so letters at a time. I put some delays into the program but they don't fully solve the problem. I'd like to remove all the delays. I am wondering if I can 1) chain the letters together and print only once or 2) erase each letter and print a new one without opening and saveing. Not sure if the problem comes from opening and saving or from the printing. All operations are within the scan loop. If I try to overwrite a document each time through the scan loop with typetext instead of insertafter, do I gain anything or is the problem in the printing with each iteration?

Here is the code
USE doaTWO
# DEFINE CRLF CHR(13)+CHR(10) 
# include wdtylb.h
RELEASE oWord
oWord = CreateObject("Word.Application")
WITH oWord
	.Visible = .t.
	.ChangeFileOpenDirectory(SYS(5)+CURDIR())
	SCAN 
		.Documents.Open("DBEN2x.doc",.f.,.f.,.f.,"","",wdOpenFormatAuto)
		.ActiveDocument.SaveAs("DBENFILLED.Doc",wdFormatDocument,.f.,"",.t.,"",.f.,.f.,.f.,.f.,.f.)
		if gotoBookMark("TODAY") = 2
	            .selection.insertafter(CMONTH(DATE())+" "+ALLTRIM(STR(day(DATE())))+", "+ALLTRIM(STR(YEAR(DATE()))))
		ENDIF
		if gotoBookMark("BENE_NAME_ADDR") = 2
			.Selection.insertafter(BENNAME+CRLF+BENADR1+CRLF+BENADR2+IIF(!EMPTY(benadr3),CRLF+BENADR3,""))
		ENDIF
		if gotoBookMark("EMPNAME") = 2
			.Selection.insertafter(EMPNAME)
		ENDIF
		if gotoBookMark("EMPNAME2") = 2
			.Selection.insertafter(ALLTRIM(EMPNAME))
		ENDIF
		if gotoBookMark("EMPNAME3") = 2
			.Selection.typetext(ALLTRIM(EMPNAME)+"    "+EMPSSNO+SPACE(15))
		ENDIF
		.printout
		.activedocument.close
	    WAIT TIMEOUT 5
	ends
    WAIT TIMEOUT 5
	.quit
endw
rele oword
CLOSE all
*********************************
func GoToBookMark
*********************************
lPara tcBookMark
if vartype(tcBookMark) # "C" or empt(tcBookMark)
	retu 0
endi
if ! oWord.ActiveDocument.BookMarks.Exists(tcBookMark)
	retu 1
endi
oWord.Selection.Goto(-1,,,tcBookMark)
retu 2
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform