Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Mailmerge: Word x Excel
Message
 
À
13/03/2006 17:33:24
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Divers
Thread ID:
01102783
Message ID:
01104314
Vues:
20
Fernando,

Here are some additional thoughts & ideas that you may find useful.

1. You may send key strokes to the Word dialogs using the approach
described in UT Message #761051 used to bypass the security dialog
introduced in OutLook 2002.

It is a stand alone EXE waiting for the dialog and sending key strokes to it.

Here is the example of the stand alone exe and for “Data Link Properties” dialog:
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
than 31 characters (which probably is not a problem in “your” Excel 2003).
After I reduced the sheet name length to 31 characters, the “Data Link
Properties” dialog disappeared!

Instead, the “Select Table” dialog appeared. It looks like the sheet is
treated as a system table and the wsqlstatement SQL statement ignored:

So, I needed the yForceMailMerge above in #1 to send key strokes to “Select Table Dialog”.
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
ENDIF
3. 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
recognized the sheet as a plain table. Still the “Select Table” dialog
appeared because it needed user confirmation to skip the first row used as a
header with field names. And again, the yForceMailMerge above in #1 helped:
if oShell.AppActivate("Select Table")
   oShell.SendKeys("{ENTER}")
ENDIF
Hope this help.

Best Wishes


>Thank you so much Yuri, your help was really very valuable!
>
>What I'm expreriencing now is the same that happended with Outlook automation with the "blessed" security patch, some time ago.
>
>I wonder what will happen with ALL Word mailmerge automation VFP programs when users upgrade to Word 2003!
>
>As stated in http://support.microsoft.com/default.aspx?scid=kb;EN-US;825765, registry editing (the MS sugested workaround) could turn into a big nightmare for some of us developers, mainly when there are strict rules in IT departments concerning this issue.
>
>>See if you can follow the Cetin' advice.
>
>Think I'll need further help on this, because I tried to open old mailmerge sets (doc, header file and data file) and experienced the same problem.
>
>Once again, thank you!
>
>Best regards,
>
>Fernando
>
>>Fernando,
>>
>>
>>I believe that you meet the MS new "SQLSecurityCheck" "feature" introduced in MS Office Word 2003 and MS Word 2002 Service Pack 3 (http://support.microsoft.com/default.aspx?scid=kb;EN-US;825765).
>>
>>In previous Word/Office versions you do not need to reconnect, but after Word2002 SP3, you need to reconnect, and then you need to bypass the Data Source user dialog. Do not know how to help here; it looks like it is "by default" when using Excel file as a Data Source.
>>
>>See if you can follow the Cetin' advice.
>>
>>
>>>Hi Yuri,
>>>
>>>>I was not able to reply via email because of:
>>>
>>>Sorry for that, I realy don't know what happened.
>>>
>>>>It is not quite clear to me, why do you need to connect again?
>>>
>>>No, I don't, but it gives me another error message if I don't try to open the data source.
>>>
>>>I sent you another set of files and snapshots (in case you can find some time to check it), showing what happens when I just doubleclik over the doc file name, and what happens when I try to run the mailmerge without issuing the opendatasourse.
>>>
>>>I really appreciate your help.
>>>
>>>Thanks so much!
>>>
>>>Fernando
>>>
>>>
>>>
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform