Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Word mailmerge with excel error
Message
From
09/07/2007 16:24:46
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Title:
Word mailmerge with excel error
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01238712
Message ID:
01238712
Views:
76
I am trying to use an excel file (created by a sql select and copy to ... type xls)
as a data source for my mail merge and I get a 'file not in the expected format' error
what am I doing wrong??


also what is the value of : wdOpenFormatAuto ?? it's not in my word10.h
lcSourceDoc = SYS(5)+CURDIR()+'Source.xls'


oWord=CREATEOBJECT("word.application")	&& Create word object
WITH oWord
	.documents.ADD
	WITH .ActiveDocument.Mailmerge
		.OpenDataSource(m.lcSourceDoc) && Set file as data source for mailmerge
		.EditMainDocument	&& Activate the main document
		.OpenDataSource(lcSourceDoc , False,False,true,False,"","","","",False,wdOpenFormatAuto,"Entire Spreadsheet","","",wdMergeSubTypeOther)

		.FIELDS.ADD(oWord.SELECTION.RANGE, NAME:= _
		"fullname"
		SELECTION.TypeParagraph
		.FIELDS.ADD(oWord.SELECTION.RANGE, "last_name")
		oWord.SELECTION.TypeParagraph
		.FIELDS.ADD(oWord.SELECTION.RANGE,"first_name")
		oWord.SELECTION.TypeParagraph
		.FIELDS.ADD(oWord.SELECTION.RANGE,"middle_name")
		oWord.SELECTION.TypeParagraph
		.FIELDS.ADD(oWord.SELECTION.RANGE,"salutation")
		oWord.SELECTION.TypeParagraph
		.FIELDS.ADD(oWord.SELECTION.RANGE,"hcity")
		oWord.SELECTION.TypeParagraph
		.FIELDS.ADD(oWord.SELECTION.RANGE,"hstate")
		oWord.SELECTION.TypeParagraph
		.FIELDS.ADD(oWord.SELECTION.RANGE,"hzip")
		oWord.SELECTION.TypeParagraph
		.FIELDS.ADD(oWord.SELECTION.RANGE,"phonenumber")
		oWord.SELECTION.TypeParagraph
		.FIELDS.ADD(oWord.SELECTION.RANGE,"email")
		oWord.SELECTION.TypeParagraph
		.FIELDS.ADD(oWord.SELECTION.RANGE,"company")
	ENDWITH
ENDWITH
WITH oWord.ActiveDocument.Mailmerge
	.Destination = wdSendToNewDocument
	.SuppressBlankLines = true
	WITH .DATASOURCE
		.FirstRecord = wdDefaultFirstRecord
		.LastRecord = wdDefaultLastRecord
	ENDWITH
	.Execute(False)
ENDWITH
Thanks

Peter
Peter Cortiel
Next
Reply
Map
View

Click here to load this message in the networking platform