Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-02-2013, 10:53 AM
donaldadams1951 donaldadams1951 is offline Find keyword in section & delete section Windows XP Find keyword in section & delete section Office 2010 32bit
Advanced Beginner
Find keyword in section & delete section
 
Join Date: Dec 2013
Location: San Francisco Bay Area
Posts: 37
donaldadams1951 is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 12-02-2013, 04:17 PM
Charles Kenyon Charles Kenyon is offline Find keyword in section & delete section Windows 7 64bit Find keyword in section & delete section Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,083
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

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
Reply With Quote
  #3  
Old 12-02-2013, 04:38 PM
macropod's Avatar
macropod macropod is offline Find keyword in section & delete section Windows 7 32bit Find keyword in section & delete section Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #4  
Old 12-02-2013, 06:15 PM
fumei fumei is offline Find keyword in section & delete section Windows 7 64bit Find keyword in section & delete section Office XP
Expert
 
Join Date: Jan 2013
Posts: 440
fumei is on a distinguished road
Default

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?
Reply With Quote
  #5  
Old 12-03-2013, 04:21 AM
macropod's Avatar
macropod macropod is offline Find keyword in section & delete section Windows 7 32bit Find keyword in section & delete section Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #6  
Old 12-03-2013, 10:08 AM
donaldadams1951 donaldadams1951 is offline Find keyword in section & delete section Windows XP Find keyword in section & delete section Office 2010 32bit
Advanced Beginner
Find keyword in section & delete section
 
Join Date: Dec 2013
Location: San Francisco Bay Area
Posts: 37
donaldadams1951 is on a distinguished road
Default

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.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find keyword in section & delete section Deleting section break and retaining section properties New Daddy Word 6 02-03-2014 07:09 PM
Find keyword in section & delete section 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
Find keyword in section & delete section Can't Delete Section Breaks with ^b cheech1981 Word 8 07-11-2012 11:48 AM
Find keyword in section & delete section Copy/Paste/Delete Table & Section etc. flds Word VBA 40 07-16-2011 07:34 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:57 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft