macro to remove item between parenthesis

I have written a 957 page book. During the creation of the book I placed many 
phrases between parenthesis to help me remember characters and dates. For 
example I have hundreds that are similar to the following: (Amy Justice 749 
-memo).  I would like a macro that will allow me to delete all occurrences of 
(xxxxx -memo). In other words it will remove anything between parenthesis, 
including the parenthesis when the end of the phrase is -memo).  This would 
be enormoulsy helpful. Otherwise I have to go through the entire book page by 
page searching for "-memo) and then highlighting the entire phrase and 
deleting it one at a time. Ahy help will be appreciated.
-- 
Butch Cassidy
0
Utf
4/4/2010 4:14:01 PM
word.docmanagement 5542 articles. 2 followers. Follow

8 Replies
3873 Views

Similar Articles

[PageSpeed] 19

Sub FindAndDeleteSpecial()
Dim oRng As Range
Set oRng = ActiveDocument.Content
With oRng.Find
  .ClearFormatting
  .Text = "\(*\)"
  .Forward = True
  .Wrap = wdFindStop
  .MatchWildcards = True
  Do While .Execute
    With oRng
      If Mid(oRng, Len(oRng) - 5, 5) = "-memo" Then oRng.Delete
      .Collapse wdCollapseEnd
    End With
  Loop
End With
End Sub



Elfego Baca wrote:
> I have written a 957 page book. During the creation of the book I
> placed many phrases between parenthesis to help me remember
> characters and dates. For example I have hundreds that are similar to
> the following: (Amy Justice 749 -memo).  I would like a macro that
> will allow me to delete all occurrences of (xxxxx -memo). In other
> words it will remove anything between parenthesis, including the
> parenthesis when the end of the phrase is -memo).  This would be
> enormoulsy helpful. Otherwise I have to go through the entire book
> page by page searching for "-memo) and then highlighting the entire
> phrase and deleting it one at a time. Ahy help will be appreciated. 


0
Greg
4/4/2010 4:48:33 PM
The line: If Mid(oRng, Len(oRng) - 5, 5) = "-memo" Then oRng.Delete  comes 
back as an error.

Am I doing something wrong or is the code a problem.

I copied and pasted the code into a new macro and then tried running the macro

-- 
Butch Cassidy


"Greg Maxey" wrote:

> Sub FindAndDeleteSpecial()
> Dim oRng As Range
> Set oRng = ActiveDocument.Content
> With oRng.Find
>   .ClearFormatting
>   .Text = "\(*\)"
>   .Forward = True
>   .Wrap = wdFindStop
>   .MatchWildcards = True
>   Do While .Execute
>     With oRng
>       If Mid(oRng, Len(oRng) - 5, 5) = "-memo" Then oRng.Delete
>       .Collapse wdCollapseEnd
>     End With
>   Loop
> End With
> End Sub
> 
> 
> 
> Elfego Baca wrote:
> > I have written a 957 page book. During the creation of the book I
> > placed many phrases between parenthesis to help me remember
> > characters and dates. For example I have hundreds that are similar to
> > the following: (Amy Justice 749 -memo).  I would like a macro that
> > will allow me to delete all occurrences of (xxxxx -memo). In other
> > words it will remove anything between parenthesis, including the
> > parenthesis when the end of the phrase is -memo).  This would be
> > enormoulsy helpful. Otherwise I have to go through the entire book
> > page by page searching for "-memo) and then highlighting the entire
> > phrase and deleting it one at a time. Ahy help will be appreciated. 
> 
> 
> .
> 
0
Utf
4/5/2010 1:32:01 PM
Greg's macro works for me, but you could make it even simpler


Sub FindAndDeleteSpecial()
Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
        .Text = "\(*-memo\)"
    Do While .Execute(Forward:=True, _
    MatchWildcards:=True) = True
        oRng.Delete
    Loop
End With
End Sub


-- 
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>



"Elfego Baca" <ElfegoBaca@discussions.microsoft.com> wrote in message 
news:C03E2D6B-8215-4F72-974A-C1B2EA944C3B@microsoft.com...
> The line: If Mid(oRng, Len(oRng) - 5, 5) = "-memo" Then oRng.Delete  comes
> back as an error.
>
> Am I doing something wrong or is the code a problem.
>
> I copied and pasted the code into a new macro and then tried running the 
> macro
>
> -- 
> Butch Cassidy
>
>
> "Greg Maxey" wrote:
>
>> Sub FindAndDeleteSpecial()
>> Dim oRng As Range
>> Set oRng = ActiveDocument.Content
>> With oRng.Find
>>   .ClearFormatting
>>   .Text = "\(*\)"
>>   .Forward = True
>>   .Wrap = wdFindStop
>>   .MatchWildcards = True
>>   Do While .Execute
>>     With oRng
>>       If Mid(oRng, Len(oRng) - 5, 5) = "-memo" Then oRng.Delete
>>       .Collapse wdCollapseEnd
>>     End With
>>   Loop
>> End With
>> End Sub
>>
>>
>>
>> Elfego Baca wrote:
>> > I have written a 957 page book. During the creation of the book I
>> > placed many phrases between parenthesis to help me remember
>> > characters and dates. For example I have hundreds that are similar to
>> > the following: (Amy Justice 749 -memo).  I would like a macro that
>> > will allow me to delete all occurrences of (xxxxx -memo). In other
>> > words it will remove anything between parenthesis, including the
>> > parenthesis when the end of the phrase is -memo).  This would be
>> > enormoulsy helpful. Otherwise I have to go through the entire book
>> > page by page searching for "-memo) and then highlighting the entire
>> > phrase and deleting it one at a time. Ahy help will be appreciated.
>>
>>
>> .
>> 


0
Graham
4/5/2010 1:54:05 PM
-- 
Butch Cassidy


"Graham Mayor" wrote:

> Greg's macro works for me, but you could make it even simpler
> 
> 
> Sub FindAndDeleteSpecial()
> Dim oRng As Range
> Set oRng = ActiveDocument.Range
> With oRng.Find
>         .Text = "\(*-memo\)"
>     Do While .Execute(Forward:=True, _
>     MatchWildcards:=True) = True
>         oRng.Delete
>     Loop
> End With
> End Sub
> 
> 
> -- 
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor -  Word MVP
> 
> My web site www.gmayor.com
> Word MVP web site http://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> 
> 
> 
> "Elfego Baca" <ElfegoBaca@discussions.microsoft.com> wrote in message 
> news:C03E2D6B-8215-4F72-974A-C1B2EA944C3B@microsoft.com...
> > The line: If Mid(oRng, Len(oRng) - 5, 5) = "-memo" Then oRng.Delete  comes
> > back as an error.
> >
> > Am I doing something wrong or is the code a problem.
> >
> > I copied and pasted the code into a new macro and then tried running the 
> > macro
> >
> > -- 
> > Butch Cassidy
> >
> >
> > "Greg Maxey" wrote:
> >
> >> Sub FindAndDeleteSpecial()
> >> Dim oRng As Range
> >> Set oRng = ActiveDocument.Content
> >> With oRng.Find
> >>   .ClearFormatting
> >>   .Text = "\(*\)"
> >>   .Forward = True
> >>   .Wrap = wdFindStop
> >>   .MatchWildcards = True
> >>   Do While .Execute
> >>     With oRng
> >>       If Mid(oRng, Len(oRng) - 5, 5) = "-memo" Then oRng.Delete
> >>       .Collapse wdCollapseEnd
> >>     End With
> >>   Loop
> >> End With
> >> End Sub
> >>
> >>
> >>
> >> Elfego Baca wrote:
> >> > I have written a 957 page book. During the creation of the book I
> >> > placed many phrases between parenthesis to help me remember
> >> > characters and dates. For example I have hundreds that are similar to
> >> > the following: (Amy Justice 749 -memo).  I would like a macro that
> >> > will allow me to delete all occurrences of (xxxxx -memo). In other
> >> > words it will remove anything between parenthesis, including the
> >> > parenthesis when the end of the phrase is -memo).  This would be
> >> > enormoulsy helpful. Otherwise I have to go through the entire book
> >> > page by page searching for "-memo) and then highlighting the entire
> >> > phrase and deleting it one at a time. Ahy help will be appreciated.
> >>
> >>
> >> .
> >> 
> 
> 
> .
> I have tried both macros. I am having the same problem with both.  The macros look for the first open parenthesis and then highlight everything up to and including the -memo) and then delete it.  For example suppose I have a paragraph that goes something like this:  asdfasdf asd asdf asdf  here it is ( asdf asd) asdf wet dfg d hdfg (123, asdf) 2etwer wertwt wert we twer (asasd -memo) asdf  asdf asdfasdfasd. 
 The macros are finding the first open paragraph after the words "here it is 
and deleting  :\"( asdf asd) asdf wet dfg d hdfg (123, asdf) 2etwer wertwt 
wert we twer (asasd -memo)." It should only delete (asasd -memo) and then 
continue looking for the next occurrence of the -memo).  My thought is that 
the macro should actually look for "-memo)" and then somehow highlight 
backwards starting from the ending parenthesis till the first occurrence of 
the opening parenthesis and then delete the entire section.  Right now, as 
the subroutines are working, the subroutine looks for the first occurrence of 
the opening parenthesis and then highlights everything until it finds the 
words in the text "memo" and the closing parenthesis and then  deletes the 
whole thing.  When I tried the subroutines on my 1000 page book it left me 
with a 40 page book and all of the rest was deleted.
0
Utf
4/6/2010 10:19:01 PM
"Elfego Baca" <ElfegoBaca@discussions.microsoft.com> wrote in message 
news:0ED697F0-0864-49C6-A56B-3A9D5A56508D@microsoft.com...
..
>> I have tried both macros. I am having the same problem with both.  The 
>> macros look for the first open parenthesis and then highlight everything 
>> up to and including the -memo) and then delete it.  For example suppose I 
>> have a paragraph that goes something like this:  asdfasdf asd asdf asdf 
>> here it is ( asdf asd) asdf wet dfg d hdfg (123, asdf) 2etwer wertwt wert 
>> we twer (asasd -memo) asdf  asdf asdfasdfasd.
> The macros are finding the first open paragraph after the words "here it 
> is
> and deleting  :\"( asdf asd) asdf wet dfg d hdfg (123, asdf) 2etwer wertwt
> wert we twer (asasd -memo)." It should only delete (asasd -memo) and then
> continue looking for the next occurrence of the -memo).  My thought is 
> that
> the macro should actually look for "-memo)" and then somehow highlight
> backwards starting from the ending parenthesis till the first occurrence 
> of
> the opening parenthesis and then delete the entire section.  Right now, as
> the subroutines are working, the subroutine looks for the first occurrence 
> of
> the opening parenthesis and then highlights everything until it finds the
> words in the text "memo" and the closing parenthesis and then  deletes the
> whole thing.  When I tried the subroutines on my 1000 page book it left me
> with a 40 page book and all of the rest was deleted.

The macro looks for a sequence that matches "\(*-memo\)"
i.e. an opening bracket followed by any amount of text until it sees -memo 
immediately followed by a closing bracket. If you have bracketed text within 
bracketed strings or if you have missing brackets, then inevitably it will 
find longer strings than you intend.
You could narrow the search by eliminating strings that contain brackets 
e.g.

Sub FindAndDeleteSpecial()
Dim oRng As Range
Dim sText As String
Set oRng = ActiveDocument.Range
With oRng.Find
        .Text = "\(*-memo\)"
    Do While .Execute(Forward:=True, _
    MatchWildcards:=True) = True
        sText = Mid(oRng.Text, 2, Len(oRng.Text) - 2)
        If InStr(1, sText, "(") = False Then
            If InStr(1, sText, ")") = False Then
                MsgBox oRng
                'orng.Delete
            End If
        End If
    Loop
End With
End Sub

which finds only (asasd -memo) in your sample text. How accurate this will 
be in finding strings in your document is hard to say, but for the purpose 
of testing I have used a message box to display the found string and 
disabled the delete function. You can disable the message box and enable the 
delete function if it works for you.

-- 
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


0
Graham
4/7/2010 6:47:02 AM
-- 
Butch Cassidy


"Graham Mayor" wrote:

> 
> "Elfego Baca" <ElfegoBaca@discussions.microsoft.com> wrote in message 
> news:0ED697F0-0864-49C6-A56B-3A9D5A56508D@microsoft.com...
> ..
> >> I have tried both macros. I am having the same problem with both.  The 
> >> macros look for the first open parenthesis and then highlight everything 
> >> up to and including the -memo) and then delete it.  For example suppose I 
> >> have a paragraph that goes something like this:  asdfasdf asd asdf asdf 
> >> here it is ( asdf asd) asdf wet dfg d hdfg (123, asdf) 2etwer wertwt wert 
> >> we twer (asasd -memo) asdf  asdf asdfasdfasd.
> > The macros are finding the first open paragraph after the words "here it 
> > is
> > and deleting  :\"( asdf asd) asdf wet dfg d hdfg (123, asdf) 2etwer wertwt
> > wert we twer (asasd -memo)." It should only delete (asasd -memo) and then
> > continue looking for the next occurrence of the -memo).  My thought is 
> > that
> > the macro should actually look for "-memo)" and then somehow highlight
> > backwards starting from the ending parenthesis till the first occurrence 
> > of
> > the opening parenthesis and then delete the entire section.  Right now, as
> > the subroutines are working, the subroutine looks for the first occurrence 
> > of
> > the opening parenthesis and then highlights everything until it finds the
> > words in the text "memo" and the closing parenthesis and then  deletes the
> > whole thing.  When I tried the subroutines on my 1000 page book it left me
> > with a 40 page book and all of the rest was deleted.
> 
> The macro looks for a sequence that matches "\(*-memo\)"
> i.e. an opening bracket followed by any amount of text until it sees -memo 
> immediately followed by a closing bracket. If you have bracketed text within 
> bracketed strings or if you have missing brackets, then inevitably it will 
> find longer strings than you intend.
> You could narrow the search by eliminating strings that contain brackets 
> e.g.
> 
> Sub FindAndDeleteSpecial()
> Dim oRng As Range
> Dim sText As String
> Set oRng = ActiveDocument.Range
> With oRng.Find
>         .Text = "\(*-memo\)"
>     Do While .Execute(Forward:=True, _
>     MatchWildcards:=True) = True
>         sText = Mid(oRng.Text, 2, Len(oRng.Text) - 2)
>         If InStr(1, sText, "(") = False Then
>             If InStr(1, sText, ")") = False Then
>                 MsgBox oRng
>                 'orng.Delete
>             End If
>         End If
>     Loop
> End With
> End Sub
> 
> which finds only (asasd -memo) in your sample text. How accurate this will 
> be in finding strings in your document is hard to say, but for the purpose 
> of testing I have used a message box to display the found string and 
> disabled the delete function. You can disable the message box and enable the 
> delete function if it works for you.
> 
> -- 
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor -  Word MVP
> 
> My web site www.gmayor.com
> Word MVP web site http://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> 
> 
> .
> Can a macro be written that simply looks for the word meme + the end parenthesis 'memo)' and then highlights backwards to a starting parenthesis, then deleting this entire highlighted text? The reason is the macro that you gave me allows me to individually delete the phrases 1 at a time, however there are 6943 instances of the word memo within an opening and closing parenthesis and I can't delete each one, one at a time for 6943 key presses.   
0
Utf
4/7/2010 10:38:01 PM
You didn't read my earlier reply!

I said that I had inserted the message box for testing to ensure that it was 
picking only the strings you requested. If you are satisfied that works then 
remove the line
 MsgBox oRng
and remove the apostrophe from the start of the line
 'orng.Delete

-- 
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

"Elfego Baca" <ElfegoBaca@discussions.microsoft.com> wrote in message 
news:28709ABF-235E-41C0-8CCE-631B473B04E6@microsoft.com...
>
> -- 
> Butch Cassidy
>
>
> "Graham Mayor" wrote:
>
>>
>> "Elfego Baca" <ElfegoBaca@discussions.microsoft.com> wrote in message
>> news:0ED697F0-0864-49C6-A56B-3A9D5A56508D@microsoft.com...
>> ..
>> >> I have tried both macros. I am having the same problem with both.  The
>> >> macros look for the first open parenthesis and then highlight 
>> >> everything
>> >> up to and including the -memo) and then delete it.  For example 
>> >> suppose I
>> >> have a paragraph that goes something like this:  asdfasdf asd asdf 
>> >> asdf
>> >> here it is ( asdf asd) asdf wet dfg d hdfg (123, asdf) 2etwer wertwt 
>> >> wert
>> >> we twer (asasd -memo) asdf  asdf asdfasdfasd.
>> > The macros are finding the first open paragraph after the words "here 
>> > it
>> > is
>> > and deleting  :\"( asdf asd) asdf wet dfg d hdfg (123, asdf) 2etwer 
>> > wertwt
>> > wert we twer (asasd -memo)." It should only delete (asasd -memo) and 
>> > then
>> > continue looking for the next occurrence of the -memo).  My thought is
>> > that
>> > the macro should actually look for "-memo)" and then somehow highlight
>> > backwards starting from the ending parenthesis till the first 
>> > occurrence
>> > of
>> > the opening parenthesis and then delete the entire section.  Right now, 
>> > as
>> > the subroutines are working, the subroutine looks for the first 
>> > occurrence
>> > of
>> > the opening parenthesis and then highlights everything until it finds 
>> > the
>> > words in the text "memo" and the closing parenthesis and then  deletes 
>> > the
>> > whole thing.  When I tried the subroutines on my 1000 page book it left 
>> > me
>> > with a 40 page book and all of the rest was deleted.
>>
>> The macro looks for a sequence that matches "\(*-memo\)"
>> i.e. an opening bracket followed by any amount of text until it 
>> sees -memo
>> immediately followed by a closing bracket. If you have bracketed text 
>> within
>> bracketed strings or if you have missing brackets, then inevitably it 
>> will
>> find longer strings than you intend.
>> You could narrow the search by eliminating strings that contain brackets
>> e.g.
>>
>> Sub FindAndDeleteSpecial()
>> Dim oRng As Range
>> Dim sText As String
>> Set oRng = ActiveDocument.Range
>> With oRng.Find
>>         .Text = "\(*-memo\)"
>>     Do While .Execute(Forward:=True, _
>>     MatchWildcards:=True) = True
>>         sText = Mid(oRng.Text, 2, Len(oRng.Text) - 2)
>>         If InStr(1, sText, "(") = False Then
>>             If InStr(1, sText, ")") = False Then
>>                 MsgBox oRng
>>                 'orng.Delete
>>             End If
>>         End If
>>     Loop
>> End With
>> End Sub
>>
>> which finds only (asasd -memo) in your sample text. How accurate this 
>> will
>> be in finding strings in your document is hard to say, but for the 
>> purpose
>> of testing I have used a message box to display the found string and
>> disabled the delete function. You can disable the message box and enable 
>> the
>> delete function if it works for you.
>>
>> -- 
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>> Graham Mayor -  Word MVP
>>
>> My web site www.gmayor.com
>> Word MVP web site http://word.mvps.org
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>>
>>
>> .
>> Can a macro be written that simply looks for the word meme + the end 
>> parenthesis 'memo)' and then highlights backwards to a starting 
>> parenthesis, then deleting this entire highlighted text? The reason is 
>> the macro that you gave me allows me to individually delete the phrases 1 
>> at a time, however there are 6943 instances of the word memo within an 
>> opening and closing parenthesis and I can't delete each one, one at a 
>> time for 6943 key presses. 


0
Graham
4/8/2010 8:05:03 AM
As I believe I said earlier it is difficult to allow for input errors. While 
missing or duplicated brackets can still cause a problem, on further 
reflection the following may be more what you had in mind. This finds the 
string
"\(*-memo\)" then searching from the end of the string seeks backwards to 
the last opening bracket in the string and moves the start of the range to 
that position before deleting the range. As an additional check, the deleted 
entries and the page numbers on which they are found are listed in a new 
document. You can thus check whether the macro works correctly with your 
document.


Sub FindAndDeleteSpecial()
Dim oRng As Range
Dim sText As String
Dim iStart As Integer
Dim iEnd As Integer
Dim oDoc As Document
Dim oNewDoc As Document
Set oDoc = ActiveDocument
Set oNewDoc = Documents.Add
Set oRng = oDoc.Range
With oRng.Find
    .Text = "\(*-memo\)"
    Do While .Execute(Forward:=True, _
    MatchWildcards:=True) = True
        iStart = InStrRev(oRng.Text, "(")
        oRng.Start = oRng.Start + (iStart - 1)
        oNewDoc.Range.InsertAfter "Page " & _
        oRng.Information(wdActiveEndPageNumber) & _
        vbTab & oRng.Text & vbCr
        oRng.Delete
    Loop
End With
End Sub

-- 
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


"Graham Mayor" <gmayor@REMOVETHISmvps.org> wrote in message 
news:e8PmrIv1KHA.264@TK2MSFTNGP05.phx.gbl...
> You didn't read my earlier reply!
>
> I said that I had inserted the message box for testing to ensure that it 
> was picking only the strings you requested. If you are satisfied that 
> works then remove the line
> MsgBox oRng
> and remove the apostrophe from the start of the line
> 'orng.Delete
>
> -- 
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor -  Word MVP
>
> My web site www.gmayor.com
> Word MVP web site http://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>
> "Elfego Baca" <ElfegoBaca@discussions.microsoft.com> wrote in message 
> news:28709ABF-235E-41C0-8CCE-631B473B04E6@microsoft.com...
>>
>> -- 
>> Butch Cassidy
>>
>>
>> "Graham Mayor" wrote:
>>
>>>
>>> "Elfego Baca" <ElfegoBaca@discussions.microsoft.com> wrote in message
>>> news:0ED697F0-0864-49C6-A56B-3A9D5A56508D@microsoft.com...
>>> ..
>>> >> I have tried both macros. I am having the same problem with both. 
>>> >> The
>>> >> macros look for the first open parenthesis and then highlight 
>>> >> everything
>>> >> up to and including the -memo) and then delete it.  For example 
>>> >> suppose I
>>> >> have a paragraph that goes something like this:  asdfasdf asd asdf 
>>> >> asdf
>>> >> here it is ( asdf asd) asdf wet dfg d hdfg (123, asdf) 2etwer wertwt 
>>> >> wert
>>> >> we twer (asasd -memo) asdf  asdf asdfasdfasd.
>>> > The macros are finding the first open paragraph after the words "here 
>>> > it
>>> > is
>>> > and deleting  :\"( asdf asd) asdf wet dfg d hdfg (123, asdf) 2etwer 
>>> > wertwt
>>> > wert we twer (asasd -memo)." It should only delete (asasd -memo) and 
>>> > then
>>> > continue looking for the next occurrence of the -memo).  My thought is
>>> > that
>>> > the macro should actually look for "-memo)" and then somehow highlight
>>> > backwards starting from the ending parenthesis till the first 
>>> > occurrence
>>> > of
>>> > the opening parenthesis and then delete the entire section.  Right 
>>> > now, as
>>> > the subroutines are working, the subroutine looks for the first 
>>> > occurrence
>>> > of
>>> > the opening parenthesis and then highlights everything until it finds 
>>> > the
>>> > words in the text "memo" and the closing parenthesis and then  deletes 
>>> > the
>>> > whole thing.  When I tried the subroutines on my 1000 page book it 
>>> > left me
>>> > with a 40 page book and all of the rest was deleted.
>>>
>>> The macro looks for a sequence that matches "\(*-memo\)"
>>> i.e. an opening bracket followed by any amount of text until it 
>>> sees -memo
>>> immediately followed by a closing bracket. If you have bracketed text 
>>> within
>>> bracketed strings or if you have missing brackets, then inevitably it 
>>> will
>>> find longer strings than you intend.
>>> You could narrow the search by eliminating strings that contain brackets
>>> e.g.
>>>
>>> Sub FindAndDeleteSpecial()
>>> Dim oRng As Range
>>> Dim sText As String
>>> Set oRng = ActiveDocument.Range
>>> With oRng.Find
>>>         .Text = "\(*-memo\)"
>>>     Do While .Execute(Forward:=True, _
>>>     MatchWildcards:=True) = True
>>>         sText = Mid(oRng.Text, 2, Len(oRng.Text) - 2)
>>>         If InStr(1, sText, "(") = False Then
>>>             If InStr(1, sText, ")") = False Then
>>>                 MsgBox oRng
>>>                 'orng.Delete
>>>             End If
>>>         End If
>>>     Loop
>>> End With
>>> End Sub
>>>
>>> which finds only (asasd -memo) in your sample text. How accurate this 
>>> will
>>> be in finding strings in your document is hard to say, but for the 
>>> purpose
>>> of testing I have used a message box to display the found string and
>>> disabled the delete function. You can disable the message box and enable 
>>> the
>>> delete function if it works for you.
>>>
>>> -- 
>>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>>> Graham Mayor -  Word MVP
>>>
>>> My web site www.gmayor.com
>>> Word MVP web site http://word.mvps.org
>>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>>>
>>>
>>> .
>>> Can a macro be written that simply looks for the word meme + the end 
>>> parenthesis 'memo)' and then highlights backwards to a starting 
>>> parenthesis, then deleting this entire highlighted text? The reason is 
>>> the macro that you gave me allows me to individually delete the phrases 
>>> 1 at a time, however there are 6943 instances of the word memo within an 
>>> opening and closing parenthesis and I can't delete each one, one at a 
>>> time for 6943 key presses.
>
> 


0
Graham
4/8/2010 9:10:48 AM
Reply:

Similar Artilces:

removing reference to other workbook
hi i have a excel wookbook which contains references to other workbook. whenever i open this wookbook it asks me for updating the link to the other workbook. i want to remove these references to other workbook but am not able to figure out which cell is refering to the other workbook. i also have lot of references in the same workbook. i dont want the internal references to be removed. can anyone help me to accomplish this task. any help is highly appretiated. thankx in advance. pradyumna Hi try the following add-in to find/delete links: http://www.bmsltd.ie/DLCount/DLCount.asp?file=FindL...

The item number is missing in line '1'
Hi, Upon using Integration manager 9.0 using the Inventory transaction (adjustment), we are encountering the error "The item number is missing in line '1' ". When I run the integration in my computer there is no error, but upon running it using other computers, this error appears. I'm using the same text files and the same mapping of fields. We are using GP 9.0. Thanks, Mel ...

Removing old email attachments
Is there a way to have Outlook automatically remove attachments from old emails in personal and public folders (ie any email older than [90] days would have the attachment(s) removed from the email). Any help would be appreciated. ...

Macro warning with no macros
I have a workbook that when I try to open it I get the warning tellin me it contains macros and asking whether I want to Enable or Disabl them. I put no macros, no VB scripts, nothing at all in the workboo other than standard Excel formulas and some charts. I developed it i Excel 2002, SP-2, but have moved it back and forth between tw computers, the other which has Excel 97. Regardless of whether Enable or Disable or change the security settings so as not to get th warning, once the workbook is open even if I go t Tools-Macro-Macros... it lists no macros. How can I find out what's cau...

Macro
Can anybody tell me how to kick off a macro automatically as file is opened? Regards ...

Removing Duplicate Values
Hello all I have a column of data made up of 100 cells. Some cells have a unique value and others the same value. Using a formula in another column, is there a way I can be left with just a list of unique values e.g. if X comes up 3 times in the original column how can I show it just once in another? I know I can use remove duplicates in excel but I don't want to as I don't want to have to use macros thanks -- James. Hi, take a look to CPearson web http://www.cpearson.com/excel/Duplicates.aspx at the end of the page there is a link as well theat will ...

Item Send
I am using a customised program that prepares & automatically sends mail to Outlook, using a Microsoft Outlook Visual Basic Application command, Item.Send. However, I have to manually click YES, for each email that is been sent to Outlook outbox (and there is a 5 second delay between each message - ie when the warning message is displayed, the Yes button is not available for 5 seconds). Is there any facility within Outlook, that will allow me to configure it, so that it allows such emails from the customised program to be sent directly to Outlook outbox (without having to click &q...

Macro
Version: 2008 Operating System: Mac OS X 10.4 (Tiger) Processor: intel Hi, I'm thinking of buying Mac: Office 2008, but before I do I want to check that I will be able to download Scritpsmart collection of templates without any glitches: <http://www.bbc.co.uk/writersroom/scriptsmart/faq.shtml> Does anyone know if I can do this? Regards, SP. In article <ee98ff5.-1@webcrossing.caR9absDaxw>, StregaItalia@officeformac.com wrote: > Version: 2008 > Operating System: Mac OS X 10.4 (Tiger) > Processor: intel > > Hi, > > I'm thinking of buying Mac: Of...

User removed Anonymous permission from Calendar...how to get it back
A user has deleted the Anonymous permissions from their calendar and I am unable to find a way to get it back. Does anyone know what can be done to add this back to their calendar. TIA In news:Xns9861A9314BAB8bobarcabca@207.46.248.16, Fuzzy Logic <bob@arc.ab.caREMOVETHIS> typed: > A user has deleted the Anonymous permissions from their calendar and > I am unable to find a way to get it back. Does anyone know what can > be done to add this back to their calendar. TIA In that user's Outlook, right-click on Calendar, properties, permissions tab. Add Anonymous, and do whate...

Run macro automatically.
How do I make a macro run automatically when a worksheet it is attached to is loaded? right click on the sheet tab>view code>left window worksheet>right window activate -- Don Guillett SalesAid Software donaldb@281.com "Excel macro" <Excel macro@discussions.microsoft.com> wrote in message news:DD7AF1E3-9263-4523-AC49-A43ABA1AB9D0@microsoft.com... > How do I make a macro run automatically when a worksheet it is attached to is > loaded? I am unable to find "activate " when I right click on worksheet. ( i assume that you are referring to the windo...

Help with macro/and or formula?
Perhaps this is a silly question, but i just can't figure out how t format this worksheet. The problem is that a lot of the cells hav numbers in them with negative signs in the back instead of in the fron (ie. 23-) and i was wondering if anyone knew of a macro/formula i coul use to quickly fix this problem for all the cells. I would b extremely grateful. Thanks -- brefed1 ----------------------------------------------------------------------- brefed15's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=3557 View this thread: http://www.excelforum.com/showthre...

Attached Toolbars Macros
Excel 2003 I have a custom tool bar, this tool bar has several items, each item is pointing to a VBA code. This tool bar is attached to the worksheet. I've copied this spreadsheet to several computers. After I copied the spreadsheet I decided to rename the spreadsheet, after I renamed the spreadsheet the Toolbar Item's macros were still pointing to the old name, I reasigned each tool bar item to the current spreadsheet, saved the spreadsheet and everything was working on my computer, but when I re-copied the new spreadsheet to other computers and I clicked on the Toolbar Item...

Deleting Unusual Recurrence of a scheduled item.
Hello, I have a strange problem. Somehow, I have an event that recurs every day until Dec 22 2005. I have no idea how this happened, but when I delete one, I don't get any message about deleting the series, meaning I have to delete this entry for each day from here to Dec 22 2005. The easy way is of course, to ignore the entry, but I would really like to clean it up. Any ideas how to do this? Thanks! Rick RWC <rcollens_SPAMONATOR_@hemmingway.com> wrote: > I have a strange problem. Somehow, I have an event that recurs every > day until Dec 22 2005. I have no ide...

Protected sheets and running macros
i have a sheet with a macro ran by a normal button at the top. Howeve when i protect the worksheet where ever i click on the sheet the macr executes. Can any one offer any advice on how to stop this? Thanks Robert -- Message posted from http://www.ExcelForum.com hi, i am not able to reproduce the problem, hence i may not be able t provide a panacea for that issue. here is what i suggest. i have a sheet that has a macro that is run when a control toolbo button (that is, not a form button) is clicked. this sheet is protected based on the user logged in. what i have don is to protect t...

Redirecting Sent Items
Hi, Exchange 2007 Environment =============================== We have having one mailbox "abc". We have given send as permision to 4 user a,b,c,d on mailbox abc. All the 4 users accessing their own mailbox and while sending some mailbox they are using from field and sending e-mail with send as permission. When the 4 users uses send as permission for mailbox abc and send's e-mail the e-mail rest in particular users sent item. Is there any way to redirect these sent messages to abc's mailbox using some tools or rules. Regards, KT There's ...

Macro to remove rows?
Hi, I receive thousands of rows of data from an extract that comes from a database. The data extract automatically generates page headers that need to be removed, and I would love to automate this process. The headers do have a pattern to them, but I'm not clever enough to figure out a good way to use that to write a macro. The first row of the header starts with hyphens ------------------------------- Then there's a variable number of rows of header data to delete followed by another row of hyphens ------------------------------- Then 2 additional rows that must be deleted. The nu...

Macro Freezes Reading Pane
I have a macro that Sends/Receives Tasks from Project Server into Outlook Tasks. Everything is working fine, except one weird thing that happens. I have the Timer set on the macro and it starts as soon as Outlook starts. The macro gets the tasks from ProjectServer every hour. As soon as the macro starts running the Reading pane freezes in the Inbox. If i stop the macro then Reading pane is back to normal. Can anyone please tell me if there is something I can do in VBA to fix this annoying issue. Thanks a lot ...

Archive command does not remove anything
We have not tried to archive since installing exchange 2003 Trying to get users in a good habit I put a warning message to tell people to start archiving to a .pst file on there local machine, It does not work for any one, this feature was fine when we used to use microsoft mail with everyones mail on their own .pst files. We click file then archive and the icon shows in the lower right corner that it is doing something but nothing leaves the inbox and no copies of messages appear in the archive folders. There are no error messages. It looks like the process has worked but nothing hap...

Calling on a macro within a macro!
Hey All!! Quick Question - How do you call up a macro within a current macro? I have one big macro and I need it to jump to several other macros when it runs! Does it matter where the other macros are stored or is it better to have them all in one module? Help appreciated Thnx! Hi Mellowe, '=============>> Public Sub Main() 'Your code Call One 'your code End Sub '<<============= '=============>> Public Sub One() MsgBox "Hi from One" End Sub '<<============= > Does it matter where the other macros are stored or ...

Can an item you have purchased in the past become a BOM?
We are currently purchasing an item from a vendor (PO history, order history etc) that we are planning on manufacturing ourselves in the next month. I've been tasked to see if there will be any issues with using the same part number we currently ORDER from a vendor to change it into a BOM in the future. I've tested this out in our test company and cannot find any reason why we cannot use the same part number - we simply would not be able to ORDER that part any longer from anyone. Has anyone else ever gone through this process before? any issues? OR is it better to give this i...

insert category Id into Items table
Can some please help me how to insert the ID from Category and Department tables into the Items table. I have the does some one have the correct SQL for this Thank you jm can u explain it further? "jm" wrote: > Can some please help me how to insert the ID from Category and Department > tables into the Items table. I have the does some one have the correct SQL > for this > Thank you > jm ...

shortcut keys to macros
Hi, Is it at all possible to assign shortcut keys to macros in Outlook? Thx, Hans ...

help Unable to record Macro !!!!!!!
I want to record a macro in excel.But as soon as I click record Macro it says "unable to record" macro. Got no help in excel help.I do this same thing in word and it's working. Please help It's urgent for me !!!1 Have a look here http://groups.google.com/groups?as_epq=unable%20to%20record&as_ugroup=microsoft.public.excel.* -- Don Guillett SalesAid Software donaldb@281.com "ash" <anonymous@discussions.microsoft.com> wrote in message news:3e0b01c42ae5$45333e00$a401280a@phx.gbl... > I want to record a macro in excel.But as soon as I click > record...

Again
This has been an issue for a few weeks now. I have observed not only an arbitrary deletion of a message that came into my Inbox about 2 minutes before, but also seeing the Deleted Items folder being completely emptied. Both actions took place within a few seconds of each other This occured with zero user input from me and there are no user recipient policies in place. The enviroment is Exchange 2000\SP3 under Windows 2k, fully patched Nothing out of the ordinary in event viewer. No recipient message policies. No nothing. Any thoughts? George Do you see vanished messages as rec...

Macro that password protects a sheet
I am attempting to create a macro that can open a protected sheet, change something, and then protect it again. I continue to have an issue with the macro not entering the password. Is this possible to do/fix? Thanks, Ryan ..open password="mypassword" -- Don Guillett SalesAid Software donaldb@281.com "Ryan" <Ryan@discussions.microsoft.com> wrote in message news:D4780ED8-CA1D-4284-97BC-3576160D998E@microsoft.com... > I am attempting to create a macro that can open a protected sheet, change > something, and then protect it again. I continue to have an iss...