Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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 | |
|
|
Similar Threads | ||||
Thread | Forum | |||
the project item cannot be copied - Macro Organizer | Microsoft Word Help | |||
Find and remove parenthesis | Microsoft Word Help | |||
Toolbar - remove item | Microsoft Word Help | |||
Macro to Paste Same Item a Specific Number of Times? | New Users | |||
VBA to remove a Menu Bar item | Microsoft Word Help |