Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Word merge
Message
From
25/03/2004 08:01:28
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Title:
Word merge
Miscellaneous
Thread ID:
00889545
Message ID:
00889545
Views:
59
I use this code for merging into word from vfp. Everithing works fine in win98 and office 97. But on win XP and office XP something goes wrong???
Local oWord, lcFileName, lcConnectionString, oFormLetter

lcFilename = ADDBS(This.cDataPath) + This.cDataSource + ".CWH"

IF EMPTY(this.cDocFolder)
	PathDoc = ""
ELSE
	PathDoc = ADDBS(ALLTRIM(this.cDocFolder))
ENDIF

FileDOC = PathDOC + ALLTRIM(this.cFileForMerge)

IF !DIRECTORY(This.cDataPath) Then
	MESSAGEBOX("Nonexistance of table : " + This.cDatapath, 0, "Error")

	RETURN .F.
ENDIF

IF !FILE(ADDBS(This.cDatapath) + This.cDataSource + ".DBF") THEN
	MESSAGEBOX("Table " + ADDBS(This.cDatapath) + This.cDataSource + ".DBF not ecist", 0, "Error")

	RETURN .F.
ENDIF

IF !FILE((FajlDOC)) THEN
	MESSAGEBOX("File " + FajlDOC + " does not exist!", 0, "Error")

	RETURN .F.
ENDIF

lcConnectionString = "DSN=DBASE Files - Word;UID=;PWD=;SourceDB=" + This.cDataPath + ";SourceType=DBF;Exclusive=No;BackgroundFetch=Yes;Collate=MACHINE;Null=Yes;Deleted=Yes;"

*On Error Do DummyError
oWord = GetObject("","Word.Application")

IF TYPE("oWord") != "O" Then
	oWord = CreateObject("Word.Application")
	IF TYPE("oWord") !="O" Then
		MESSAGEBOX("Could not start WORD", 0, "Error")

		RETURN .F.
	ENDIF
ENDIF

WITH oWord
	.visible=.t.
ENDWITH

lnSelectArea=select()
oWord.Documents.Open((FajlDOC), .F., .F., .F., "", "", .F., "", "", 0)
oFormLetter = oWord.ActiveDocument

oWord.ActiveDocument.MailMerge.OpenDataSource(lcFilename)

WITH oWord.ActiveDocument.MailMerge
	.Destination = 0
	.MailAsAttachment = .F.
	.MailAddressFieldName = ""
	.MailSubject = ""
	.SuppressBlankLines = .F.
	WITH .DataSource
		.FirstRecord = 1
		.LastRecord = -16
	ENDWITH
	.Execute(.T.)
ENDWITH

oFormLetter.Close(0)

IF THIS.lSave and !EMPTY(This.cSaveAsName) THEN
	IF !EMPTY(This.cSaveAsFolder) THEN
		oWord.ChangeFileOpenDirectory(This.cSaveAsFolder)
	ENDIF

	oWord.ActiveDocument.SAVEAS(This.cSaveAsName, 0)
ENDIF
Error appears on OPEN line of code. Error message is something like "file xx.doc does not exist" but there is xx.doc for sure.
Next
Reply
Map
View

Click here to load this message in the networking platform