Hi, i've an app with mailing option for my customers and it's run ok with Word 2010 or below, but when it run with Word 2013 show an error.
The code is the following:
*----------------------------------------------------------------------------------------------------------------
Parameters lcBuscar, lcReemplazo, lReemplazo
#Define wdReplaceOne 1
#Define wdFindContinue 1
#Define wdStory 6
#Define wdPasteDefault 0
oWord.Selection.HomeKey(wdStory) && Inicio del Documento
oWord.Selection.Find.ClearFormatting
With oWord.Selection.Find
oWord.Selection.HomeKey(wdStory) && Inicio del Documento
oWord.Selection.Find.ClearFormatting
With oWord.Selection.Find
.Text = Alltrim(lcBuscar)
If Len(lcReemplazo)<=254
.Replacement.Text = lcReemplazo
Endif
.Forward = .T.
.Wrap = wdFindContinue
.Format = .F.
.MatchCase = .F.
.MatchWholeWord = .F.
.MatchWildcards = .F.
.MatchSoundsLike = .F.
.MatchAllWordForms = .F.
Endwith
.Forward = .T.
.Wrap = wdFindContinue
.Format = .F.
.MatchCase = .F.
.MatchWholeWord = .F.
.MatchWildcards = .F.
.MatchSoundsLike = .F.
.MatchAllWordForms = .F.
If Len(lcReemplazo)>254
If lReemplazo
_Cliptext = lcReemplazo && Copio los datos en memoria de Windows para pegarlo en Word
If oWord.Selection.Find.Execute
oWord.Selection.Paste
Endif
Else
Return .T.
Endif
Else
If oWord.Selection.Find.Execute
If lReemplazo
#Define wdReplaceAll 2
oWord.Selection.Find.Execute ( , , , , , , , , , , wdReplaceAll)
Else
Return .T.
Endif
Else
Return .F.
Endif
Endif
Endwith
*------------------------------------------------------------------------------------------------
Is the 'wdReplaceAll' where error is shown.
On the other hand i've tried to other thing, is change the text with next code:
local cMyFile
cMyFile=''
cMyFile=getfile("doc;rtf","Procesar","Abrir",0,"Procesar documento")
if !empty(cMyFile)
oWord = CreateObject("Word.Application")
oDoc = oWord.Documents.Open(cMyFile)
oDoc.Content.FormattedText=Strtran(oDoc.Content.text,"cambiar","reemplazamos")
oWord.visible=.T.
endif
And this code change the text fine, but the text format is lost.
How i can change the text without lost the format
The code is the following:
*----------------------------------------------------------------------------------------------------------------
Parameters lcBuscar, lcReemplazo, lReemplazo
#Define wdReplaceOne 1
#Define wdFindContinue 1
#Define wdStory 6
#Define wdPasteDefault 0
oWord.Selection.HomeKey(wdStory) && Inicio del Documento
oWord.Selection.Find.ClearFormatting
With oWord.Selection.Find
oWord.Selection.HomeKey(wdStory) && Inicio del Documento
oWord.Selection.Find.ClearFormatting
With oWord.Selection.Find
.Text = Alltrim(lcBuscar)
If Len(lcReemplazo)<=254
.Replacement.Text = lcReemplazo
Endif
.Forward = .T.
.Wrap = wdFindContinue
.Format = .F.
.MatchCase = .F.
.MatchWholeWord = .F.
.MatchWildcards = .F.
.MatchSoundsLike = .F.
.MatchAllWordForms = .F.
Endwith
.Forward = .T.
.Wrap = wdFindContinue
.Format = .F.
.MatchCase = .F.
.MatchWholeWord = .F.
.MatchWildcards = .F.
.MatchSoundsLike = .F.
.MatchAllWordForms = .F.
If Len(lcReemplazo)>254
If lReemplazo
_Cliptext = lcReemplazo && Copio los datos en memoria de Windows para pegarlo en Word
If oWord.Selection.Find.Execute
oWord.Selection.Paste
Endif
Else
Return .T.
Endif
Else
If oWord.Selection.Find.Execute
If lReemplazo
#Define wdReplaceAll 2
oWord.Selection.Find.Execute ( , , , , , , , , , , wdReplaceAll)
Else
Return .T.
Endif
Else
Return .F.
Endif
Endif
Endwith
*------------------------------------------------------------------------------------------------
Is the 'wdReplaceAll' where error is shown.
On the other hand i've tried to other thing, is change the text with next code:
local cMyFile
cMyFile=''
cMyFile=getfile("doc;rtf","Procesar","Abrir",0,"Procesar documento")
if !empty(cMyFile)
oWord = CreateObject("Word.Application")
oDoc = oWord.Documents.Open(cMyFile)
oDoc.Content.FormattedText=Strtran(oDoc.Content.text,"cambiar","reemplazamos")
oWord.visible=.T.
endif
And this code change the text fine, but the text format is lost.
How i can change the text without lost the format