>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.
Never be sure it exists if it's saying "file xx.doc does not exist" :)
Does FajlDOC vaiable hold the fullpath or name only ? Be sure it has fullpath.
PS: After you get it working I suggest not to use GetObject() but CreateObject() with word.
Cetin