Veelgestelde vragen voor zelfhulp.

Bekijk snel de veelgestelde vragen (en antwoorden) in de standaardlijst. Als u niet kunt vinden wat u zoekt, begin dan met het selecteren van uw Ability Office -versie en verfijn deze dan door zoektekst en/of categorie in te voeren.

Kennisbank artikel 98

How to search and replace in Write

Suppose you had a template and wanted to search and replace a "field holder" with some text of your own. For example, in your document you type *namefld* where you want a user name to appear and *addfld* where the address should appear. The following subroutine implements a search and replace in the active document:

Sub FindAndReplace(find, replace)
Set mydoc = ActiveDocument
stxt = mydoc.Text.Mid(0, mydoc.Text.Count)

i = InStr(stxt, find) - 1
n = Len(find)
If (i > 0) Then
mydoc.Text.Delete i, n
mydoc.Text.Insert i, replace
End If
End Sub

And the following subroutine calls the above sub with some real data:

Sub TestReplace
FindAndReplace "*namefld*", "Phil Roach"
FindAndReplace "*addfld*", "Ability, London, England"
End Sub