Clear text between specified characters

T

Tomislav

Hello,

i am new to Visual Basic and I am trying to make some macros for automated
dictionary reversing. What I must do is find all ranges between characters
"=" and "\" , and then clear them including ending sign "\". I tried few
methods and it always turns out wrong.

Can anyone help ?

Thanks

Tom
 
A

Anne Troy

Hi, Tom. There's an EXT in the status bar in Word. See it? That EXTENDS your
selection. So I would do a Find on "=" and then hit the right arrow key
once. Hit the EXT, and then do a Find for "\", and then hit Shift+Left
arrow. That should select if you're recording. How to loop? I dunno! :)
*******************
~Anne Troy

www.OfficeArticles.com
www.MyExpertsOnline.com
 
H

Helmut Weber

Hi Tomislav,

not quite clear if you want to remove the "=", too.

If so:

Sub Test9082()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
ResetSearch
With rDcm.Find
.Text = "=*\\" ' quoted backslash
.Replacement.Text = ""
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
ResetSearch
End Sub

Public Sub ResetSearch()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
End Sub

If not, then replace what you have found by "=".

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
R

Russs

I just read this message thread and my response might be too late, but I
thought others might be able to benefit from what I am writing below.
On 6/23/05 8:15 AM, in article
(e-mail address removed), "Helmut Weber"
Hi Tomislav,
not quite clear if you want to remove the "=", too.
If so:
Sub Test9082()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
ResetSearch
With rDcm.Find
.Text = "=*\\" ' quoted backslash
Sometimes the wildcard * can be too 'greedy' by crossing more than one line
to pair up the characters preceding and following the asterisk.

"The computer will do what I ask it to, not necessarily what I want it to
do!"

Something like:

.Text = "=[!=\n]@\\"

might be more appropriate if you don't want to select more than one line.

The [!=\n]@ wildcard combination replacing the * means: one or more
characters as long they are not another '=' character or a '\n' (new line)
character. That will help 'restrict' what is selected as the computer is
searching for the next backslash to pair up with the last closest equals
sign and have both on the same line.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top