[AccessD] OT: Word - Find and replace in the text box

Ervin Brindza viner at EUnet.yu
Fri Mar 18 04:37:54 CST 2005


Hi,
I just found a solution on http://word.mvps.org
Sorry for increasing List traffic...
Ervin
PS Feel free to ask for the solution privately!

----- Original Message -----
From: "Ervin Brindza" <viner at EUnet.yu>
To: <AccessD at databaseadvisors.com>
Sent: Thursday, March 17, 2005 2:44 PM
Subject: [AccessD] OT: Word - Find and replace in the text box


> Hi,
> I'm doing some Word automation. There is a .doc file with my control names
from the Access form, and in the .doc file these control names have to be
replaced with control's values.
> E.g. In the .doc file is:
> My name is txtName . And the procedure ReplacePara replaces the text
txtName to the text box value from Access.  And in .doc file is: My name is
Ervin. My problem is that the text txtName in the .doc file is in text box!,
and the sub ReplacePara can't enter into text box(it works fine with
"ordinary" text). How can I find and replace some text in text boxes? The
backgound of a .doc file is an inserted picture(can't put it in watermark
because it is too light) .
> TIA
>     Ervin
>
>
> '
> Private Sub ReplacePara(Header As String, Data As String)
> ObjWord.ActiveDocument.Content.Find.Execute FindText:=Header, _
>         ReplaceWith:=Data, Replace:=wdReplaceAll
> End Sub
>
>
> Private Sub DeletePara(Header As String, Keep As Boolean)
>
> 'Loop ensures that all occurences are replaced
> 'Forward and backward loops ensure that all occurences (ahead or behind)
> '      current cursor position are replaced
>
> With ObjWord.Selection.Find
>     .ClearFormatting
>     Do While .Execute(FindText:=Header, Forward:=True, _
>             Format:=True) = True
>             If Keep = False Then
>                 Call ObjWord.Selection.MoveDown(wdParagraph, 1, wdExtend)
>             End If
>             ObjWord.Selection.Delete
>     Loop
> End With
>
> With ObjWord.Selection.Find
>     .ClearFormatting
>     Do While .Execute(FindText:=Header, Forward:=False, _
>             Format:=True) = True
>             If Keep = False Then
>                 Call ObjWord.Selection.MoveDown(wdParagraph, 1, wdExtend)
>             End If
>             ObjWord.Selection.Delete
>     Loop
> End With
>
> End Sub
>
> Private Sub ChekControls()
> ' Use the Tag property of the control to decide which ones
> '       will be used for reporting
>
> Dim Ctrl As Control
> For Each Ctrl In Me.Form
>
>         If IsNull(Ctrl.Value) Or Len(Trim(Ctrl.Value)) = 0 Then
>             Call DeletePara(Ctrl.Name, False)
>         Else
>             Call ReplacePara(Ctrl.Name, Ctrl.Value)
>         End If
>     Next Ctrl
> End Sub
>
>
>
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com




More information about the AccessD mailing list