How to insert the space into selection range?

A

avkokin

There is text which has some words (and phrases) which enclosure
brackets. Example: "Some text (has has) words.".
I need to change text within brackets (exclude brackets) to space. I
use follow code (below), but I can't insert space into brackets. Help
me, please.
N.B. Of course, I can simply using dialog Find and Replace, but I want
to do it by this code and with range. Thank you very much.
My code:
Sub delText()
Dim oRange As Range
Dim dt As String
'Set oRange = ActiveDocument.Range
Selection.HomeKey wdStory
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "\(*\)"
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
While .Execute
Selection.MoveStart Unit:=wdCharacter, Count:=1
Selection.MoveLeft wdCharacter, 1, wdExtend
Selection.Delete
Wend
End With
Selection.HomeKey wdStory
End Sub
 
A

avkokin

I can insert spaces into brackets (the code below), but can I do it
with above macro?
Sub delTextBetweenBrackets()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "\(*\)"
.Replacement.Text = "( )"
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
End Sub
 
A

avkokin

Hello. I solved this problem with follow code:

Sub replaceTextOnSpaces()
Selection.HomeKey wdStory
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "\(*\)"
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
While .Execute
Selection.MoveStart Unit:=wdCharacter, Count:=1
Selection.MoveLeft wdCharacter, 1, wdExtend
Selection.InsertSymbol CharacterNumber:=32
Wend
End With
Selection.HomeKey wdStory
End Sub

Thank you.
 

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