Procedure yForceMailMarge lParameter pnTimeOut, pnCheckInterval * parameters can be passed as two numbers, as two character numeric expression or * as a string where two numbers are separated by space * 60000,1000 && check every 1 sec and close in 1 min * "60000","1000" * "60000 1000" if version(2)=0 _screen.left=-5000 endif do case case type("pnCheckInterval")="N" case type("pnCheckInterval")="C" and isdigit(pnCheckInterval) pnCheckInterval=val(pnCheckInterval) case type("pnTimeOut")="C" and " "$ALLTRIM(pnTimeOut) pnCheckInterval=val(; SUBSTR(ALLTRIM(pnTimeOut),rAT(" ",ALLTRIM(pnTimeout))+1)) otherwise pnCheckInterval=500 &&0.5 sec endcase do case case type("pnTimeOut")="N" case type("pnTimeOut")="C" and isdigit(pnTimeOut) pnTimeOut=val(pnTimeOut) otherwise pnTimeOut=60000 &&1 min endcase PRIVATE oShell, LtimerOL, Starttime starttime=SECONDS() oShell = CreateObject("WScript.Shell") LtimerOL=createobject("force",pnTimeOut,pnCheckInterval) read events LtimerOL=.NUll. oShell=.Null. Return *---------------------------------------- Define class force as Timer Interval = 1000 Name = "force" timeoutdef = 60000 Procedure INIT Lparameter pnTimeOut, pInterval if type("pnTimeOut")="N" this.timeoutdef=pnTimeOut endif if type("pInterval")="N" this.Interval=pInterval ENDIF endproc Procedure Timer if oShell.AppActivate("Data Link Properties") oShell.SendKeys("{ENTER}") ENDIF *You may add here other windows titles and key combinations if needed. IF SECONDS()-starttime>=this.timeoutdef/1000 clear events ENDIF Endproc Enddefine *----------------------------------------2. I tested your “mailmerge” program in the Office 2002 SP3, using connection strings based on available DSN, providers, etc:
wconn= [Provider=Microsoft.Jet.OLEDB.4.0;]+; [Data Source=]+SelArqDados+[;]+; [Mode=Write;Extended Properties=""HDR=YES;IMEX=1""]or
wconn= "DRIVER={Microsoft Excel Driver (*.xls)};" + ; "DefaultDir=c:\;" + ; "DBQ="+SelArqDados+[;],and using Sqlstatement:
wsqlstatement = "SELECT * from 'informe de rendimentos financei$'"
as parameters for: .ActiveDocument.MailMerge.OpenDataSource(SelArqDados, ; wdOpenFormatAuto,; .f.,; .f.,; .t.,; .f.,; "",; "",; .f.,; "",; "",; wconn,; wsqlstatement; )What I have found that neither of them accept Excel spreadsheet names longer
if oShell.AppActivate("Select Table") oShell.SendKeys("%O") && initiate subdialog to choose the System Tables oShell.SendKeys("{DOWN}{DOWN}=") && go to the System Tables tab and mark it oShell.SendKeys("{ENTER}") && go back to main "Select Table" dialog oShell.SendKeys("{TAB}{ENTER}") && close "Select Table" dialog ENDIF3. Less pain I got when using this:
.ActiveDocument.MailMerge.OpenDataSource(SelArqDados, ;
wdOpenFormatAuto,;
.f.,;
.f.,;
.t.,;
.f.,;
"",;
"",;
.f.,;
"",;
"",;
"Entire Spreadsheet")
Still it required the sheet name having no more than 31 characters, but it if oShell.AppActivate("Select Table") oShell.SendKeys("{ENTER}") ENDIFHope this help.