14 de junio de 2016

Buscar y Reemplazar en un documento Word

Ejemplo de buscar y reemplazar en un documento Word

wordFindAndreplace("foxpro","FoxPro","c:\informe.doc")

FUNCTION wordFindAndReplace
  LPARAMETERS cValueTofind,cValueToreplace,cDocument
  LOCAL lValue
  oWord = CREATEOBJECT("word.application")
  oDocument = oWord.Documents.OPEN(cDocument)
  loSelection = oWord.SELECTION
  WITH loSelection.FIND
    .TEXT = cValueToFind
    .Forward = .T.
    .WRAP= 1
  ENDWITH
  DO WHILE .T.
    lValue = loSelection.FIND.Execute
    IF lValue
      loSelection.Cut
      loSelection.InsertBefore(cValueToReplace)
      loselection.MoveRight
    ELSE
      EXIT
    ENDIF
  ENDDO
  oWord.VISIBLE =.T.
ENDFUNC

Mauricio Henao Romero

No hay comentarios. :

Publicar un comentario