Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
Elfego Baca Elfego Baca is offline
external usenet poster
 
Posts: 14
Default 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
  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Greg Maxey[_2_] Greg Maxey[_2_] is offline
external usenet poster
 
Posts: 668
Default macro to remove item between parenthesis

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.



  #3   Report Post  
Posted to microsoft.public.word.docmanagement
Greg Maxey[_2_] Greg Maxey[_2_] is offline
external usenet poster
 
Posts: 668
Default macro to remove item between parenthesis

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.



  #4   Report Post  
Posted to microsoft.public.word.docmanagement
Elfego Baca Elfego Baca is offline
external usenet poster
 
Posts: 14
Default macro to remove item between parenthesis

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.



.

  #5   Report Post  
Posted to microsoft.public.word.docmanagement
Elfego Baca Elfego Baca is offline
external usenet poster
 
Posts: 14
Default macro to remove item between parenthesis

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.



.



  #6   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default macro to remove item between parenthesis

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" wrote in message
...
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.



.



  #7   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default macro to remove item between parenthesis


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" wrote in message
...
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.



.



  #8   Report Post  
Posted to microsoft.public.word.docmanagement
Elfego Baca Elfego Baca is offline
external usenet poster
 
Posts: 14
Default macro to remove item between parenthesis


--
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" wrote in message
...
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.
  #9   Report Post  
Posted to microsoft.public.word.docmanagement
Elfego Baca Elfego Baca is offline
external usenet poster
 
Posts: 14
Default macro to remove item between parenthesis


--
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" wrote in message
...
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.
  #10   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default macro to remove item between parenthesis


"Elfego Baca" wrote in message
...
..
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





  #11   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default macro to remove item between parenthesis



"Elfego Baca" wrote in message
...
..
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



  #12   Report Post  
Posted to microsoft.public.word.docmanagement
Elfego Baca Elfego Baca is offline
external usenet poster
 
Posts: 14
Default macro to remove item between parenthesis


--
Butch Cassidy


"Graham Mayor" wrote:


"Elfego Baca" wrote in message
...
..
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.

  #13   Report Post  
Posted to microsoft.public.word.docmanagement
Elfego Baca Elfego Baca is offline
external usenet poster
 
Posts: 14
Default macro to remove item between parenthesis


--
Butch Cassidy


"Graham Mayor" wrote:


"Elfego Baca" wrote in message
...
..
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.

  #14   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default macro to remove item between parenthesis

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" wrote in message
...

--
Butch Cassidy


"Graham Mayor" wrote:


"Elfego Baca" wrote in message
...
..
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.



  #15   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default macro to remove item between parenthesis

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" wrote in message
...

--
Butch Cassidy


"Graham Mayor" wrote:


"Elfego Baca" wrote in message
...
..
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.





  #16   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default macro to remove item between parenthesis

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" wrote in message
...
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" wrote in message
...

--
Butch Cassidy


"Graham Mayor" wrote:


"Elfego Baca" wrote in message
...
..
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.





  #17   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default macro to remove item between parenthesis

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" wrote in message
...
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" wrote in message
...

--
Butch Cassidy


"Graham Mayor" wrote:


"Elfego Baca" wrote in message
...
..
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.





Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
the project item cannot be copied - Macro Organizer OrderedChaos Microsoft Word Help 0 August 4th 09 02:19 AM
Find and remove parenthesis Tammy Microsoft Word Help 3 April 23rd 08 06:10 PM
Toolbar - remove item Larry_from_Los_Angeles Microsoft Word Help 1 March 23rd 08 02:01 AM
Macro to Paste Same Item a Specific Number of Times? KN New Users 1 August 2nd 06 08:55 PM
VBA to remove a Menu Bar item Dennis Microsoft Word Help 3 April 6th 05 12:27 AM


All times are GMT +1. The time now is 12:48 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"