Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-16-2017, 01:34 AM
Productivity Productivity is offline Macro to search for a particular word, copy the entire paragraph to a new document Windows 10 Macro to search for a particular word, copy the entire paragraph to a new document Office 2010 64bit
Novice
Macro to search for a particular word, copy the entire paragraph to a new document
 
Join Date: Aug 2017
Posts: 1
Productivity is on a distinguished road
Default Macro to search for a particular word, copy the entire paragraph to a new document

Dear colleagues
I need help to create a macro.

I have a document about 100 pages . The document is already arranged in paragraphs.

I need to go into that existing document on the screen and then use a macro that performs the following functions.

Search for the particular word which I would input into the macro . Say I need to search for President.

Wherever that word President appears in any paragraph the macro must extract the entire text in that paragraph
in which that word President appears.

The macro must place all those extracted paragraphs into one which contain the word President


into a new document or the bottom or top of the existing document.

Some help will be much appreciated
Reply With Quote
  #2  
Old 08-16-2017, 02:10 AM
macropod's Avatar
macropod macropod is offline Macro to search for a particular word, copy the entire paragraph to a new document Windows 7 64bit Macro to search for a particular word, copy the entire paragraph to a new document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

Try:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim strFnd As String, DocSrc As Document, DocTgt As Document
strFnd = InputBox("What is the Text to Find")
If Trim(strFnd) = "" Then Exit Sub
Set DocSrc = ActiveDocument: Set DocTgt = Documents.Add
With DocSrc.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = strFnd
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute
  End With
  Do While .Find.Found
    DocTgt.Characters.Last.FormattedText = .Paragraphs(1).Range.FormattedText
    .End = .Paragraphs(1).Range.End
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 10-25-2019, 06:40 AM
EskoBrummel EskoBrummel is offline Macro to search for a particular word, copy the entire paragraph to a new document Windows 10 Macro to search for a particular word, copy the entire paragraph to a new document Office 2019
Novice
 
Join Date: Oct 2019
Posts: 1
EskoBrummel is on a distinguished road
Default Additional Features Possible?

Greetings,
This is a very useful macro, though is it possible to add the following features?
- Add the page number and document title where the paragraph is located above each paragraph;
- Enable search and extraction for multiple terms;
- Performing this macro over multiple documents.

Any of these features would be greatly appreciated!
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create Word macro to delete text throughout the entire document JTell Word VBA 8 07-06-2022 12:19 PM
Copy the entire paragraph in wildcards asderam Word VBA 0 01-28-2021 05:54 PM
Macro to search for a particular word, copy the entire paragraph to a new document Delete entire paragraph after key word jeffreybrown Word 2 07-27-2018 02:29 PM
Macro to search for a particular word, copy the entire paragraph to a new document How to select and copy to clipboard an entire document except for a paragraph and keep formatting TD_123 Word VBA 7 06-16-2015 03:30 PM
Macro to search for a particular word, copy the entire paragraph to a new document align just ONE paragraph, not the entire document vcolemonts Word 1 02-18-2014 09:57 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:22 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