'Dim wordDoc As Word.Document = (_filename, False, False, False, miss, miss, miss, miss) 'NO Recomendada,arrojara error en metodos y propiedades Pero con el tipo "Word.Document" se tendrá alguna clase de error debido a las implementaciones distintas (Yoĭesconozco exactamente cuales son estas diferencias, pero existen).ĭe esta manera el codigo ideal seria asi: Public Shared Sub ReemplazarTextoEnWord(ByVal _filename As String, ByVal texto As String, ByVal textoNuevo As String)ĭim miss As Object = ĭim wordDoc As Object = (_filename, False, False, False, miss, miss, miss, miss) 'Recomendada,funciona muy bien Por ello lo unico que deberiamos cambiar en nuestra implementacion es la declaracion "Dim wordDoc As .Document" por "Dim wordDoc As Object"Įl tipo "Object" soportará la instancia arrojada por "Documents.Open" o "" y las llamadas a sus metodos y propiedades funcionaran. ".()." proviene de otra implementacion diferente a "." Por ese motivo el metodo "Execute" de ".(,)." proviene de otra implementacion diferente a "."ĭe la misma manera. Sucede que al parecer despues de cierta version del Office (2003, 2007, etc), la clase ".Document" no tiene o no implementa cierta interfaz que genera "." o ".". No se trata de enlaces ni de cosas por el estilo. Tuve un problema con el word y despues de tanto problema y de tanto buscar por la web y probar un monton de combinaciones y hacer las variantes posible di con la solucion y encontre el ¿POR QUE? del problema que tu llamas "early binding" o enlace prematuro.Realmente Yo encontre el problema my dear GrimstoneX (I have the solution and the best form)
#Microsoft word find and replace using vba code#
there is ong good document including demo project, code sample and detailed instruction. (FindText:= "VB" , ReplaceWith:= "Visual Basic Express" , Replace:=) Object, ByVal e As System.EventArgs) Handles Button1.Clickĭim objDoc As Word.Document = ( "C:\Trydata\1.doc" ) Private Sub Button1_Click( ByVal sender As System. Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.Imports Word = Execute FindText:="", ReplaceWith:="", _ The selection remains unchanged because the Find object is accessed from a Range object (the Content property returns a Range object). To find and replace formatting, set the find and replace text to empty strings ("") and set the Format argument of the Execute method to True. The Bold property is True for the Find object and False for the Replacement object. The following example removes bold formatting in the active document. Execute Replace:=wdReplaceAll, Forward:=True, _ The selection changes when the find criteria is found because the Find object is accessed from the Selection object. The following example replaces all occurrences of the word "hi" with "hello". The Replacement object is available from the Find object. The properties and methods of the Replacement object correspond to the options in the Find and Replace dialog box ( Edit menu). The Replacement object represents the replace criteria for a find and replace operation. The following example performs the same result as the previous example, using arguments of the Execute method. If the find operation is successful, the range is redefined and bold formatting is applied to the word "blue." With The following example locates the first occurrence of the word "blue" in the active document. If the Find object is accessed from a Range object, the selection is not changed but the Range is redefined when the find criteria is found. FindText:="Hello", _įinding text without changing the selection You can set the individual properties of the Find object or use arguments with the Execute method, as shown in the following example. The Find object includes properties that relate to the options in the Find and Replace dialog box. The following example selects the next occurrence of the word "Hello." If the end of the document is reached before the word "Hello" is found, the search is stopped. If the Find object is accessed from the Selection object, the selection is changed when the find criteria is found. The find action differs slightly depending upon whether you access the Find object from the Selection object or the Range object. The Find object is available from the Selection object and the Range object. Finding and replacing is exposed by the Find and Replacement objects.