#1
|
|||
|
|||
Find keyword in section & delete section
Word 2010
I have paragraphs that contain unique keywords. I now want to find the section(continuous) that contain the keyword and delete this section and its content. |
#2
|
|||
|
|||
While this could be done, it is a lot of work, for me, to code. What is it you are trying to accomplish and why won't doing it manually work for you? Also, section breaks carry a lot of other formatting code with them. What do you want to do with that formatting?
Sections / Headers and Footers in Microsoft Word 2007-2013 |
#3
|
||||
|
||||
Cross-posted at: http://www.vbaexpress.com/forum/show...ins-my-keyword
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#4
|
|||
|
|||
Not only does deleting sections affect formatting, if you have headers or footers, this can cause havoc. I am with Charles, what exactly are you trying to accomplish? And is a code solution really required?
|
#5
|
||||
|
||||
Using a wildcard Find/Replace, it could be done with:
Find = ^m*MyWord*^m Replace = nothing. Do note, though, that any manual page breaks within the Section will cause the Find/Replace boundaries from wherever 'MyWord' is to stop at that point. It also won't work on the document's first or last Sections. There are other issues to consider too, quite apart from the formatting & header/footer issues raised by Charles & Fumei. For example, if whatever process you're using to create these Sections does not always enclose the insertion in two Section breaks, or if the insertion has Section breaks of its own, you'll run into problems, some of which will be insurmountable with a Section-based approach.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#6
|
|||
|
|||
Thanks for the input...
This is what I did to remove the sections and text I inserted into the document. Code:
strSearchString = "Inst#: " & ReportInstance With Selection.Find .ClearFormatting .Replacement.ClearFormatting .Text = strSearchString .Replacement.Text = "" .Forward = True .Wrap = wdFindStop .Format = False .MatchWildcards = True .Execute ' what section am I in? If .Found = True Then intSectionCount = ActiveDocument.Range(0, Selection.Range.End).Sections.Count ActiveDocument.Sections(intSectionCount).Range.Delete End If End With Last edited by donaldadams1951; 12-03-2013 at 11:08 PM. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Deleting section break and retaining section properties | New Daddy | Word | 6 | 02-03-2014 07:09 PM |
Section Break (Next Page) replaces Section Break (Continuous) when deleted | Carlabasson | Word | 2 | 03-25-2013 10:13 PM |
Footnotes in one column section forcing two column section start from a new page... | thorin | Word | 1 | 12-19-2012 01:22 PM |
Can't Delete Section Breaks with ^b | cheech1981 | Word | 8 | 07-11-2012 11:48 AM |
Copy/Paste/Delete Table & Section etc. | flds | Word VBA | 40 | 07-16-2011 07:34 AM |