Saturday, November 28, 2015
How To Removing Email address from MicrosoftWord text
A Word uses the < and > symbols to mean something specific in its search and replace operation. In the normal find and replace, you can use < and > to mark the start and end of a word alongside the character to stand for any set of letters.If you had <M*y> you could find Many, Mystery May and so on. This is awkward when the text you’re searching for is in triangular brackets.
Its fiddly to do a find and replace using Words standard Find/Replace option, so one alternative is to use a macro. First select the block of text containing the names and email addresses. If you had Jose Jhon <Jose.Jhon@ourco.co.uk>, Duck Donlad <Duck.Donald@ourco.co.uk you’d select just that block of text within your document. Running the macro would convert it to, Jose Jhon Duck Donald. The macro looks like this:
Sub removeeadd()
D1m 1Count. 1Count2 AS Integer
D1m strText. strText2 As String
strText — Selectlon.Text
strText2 — ""
1Count — 1
Do While 1Count <— Len(strText)
If Mid(strText. 1Count. 1) Like
"<" Then
·start of an email address
1Count2 — 1Count + 1
Do While Mid(strText. 1Count2. 1)
<> ">"
1Count2 — 1Count2 + 1
Loop
1Count — 1Count2 + 1
Else
strText2 — strText2 +
Mid(strText. 1Count. 1)
1Count — 1Count + 1
End If
Loop
Selection.TypeText (strText2)
End Sub
Word VBA has lots of sophisticated ways to carry out search and replace, but most aren’t available in this case; the string we want to replace starts with < and ends with >, and that confuses the Find/Replace options. The macro consists of two loops one within another. The outer loop moves through the selected text one character at a time looking for a < character. Each time a character that isn’t<is found, it is added to a new string. In our example, the loop would find M,then i,then c,then k,and so on, and by the time the < is found, the second string would contain Jose John. Once a < is found, the inner loop moves through the text one character at a time until a> is found, signalling the end of the email address.
This completes that run of the inner loop.We’re back in the outer loop until the next < is found. When the last line of the macro is reached, the current text selection is replaced by the second string using:
Selection.TypeText (strText2)
Labels:
MicrosoftWord
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment