Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 02-05-2017, 03:58 PM
Demonic Demonic is offline Macro for copying text between two Words. Windows 10 Macro for copying text between two Words. Office 2013
Novice
Macro for copying text between two Words.
 
Join Date: Feb 2017
Posts: 2
Demonic is on a distinguished road
Default Macro for copying text between two Words.

Hello I'm trying to make a Macro that can copy the text between 2 arbitrary words. The Macro I found(and slightly altered) works perfectly, with 1 problem. I don't know how to loop it so that it finds all instances of the words in the entire Document.

To show exactly what the macro is intended to do here is a screenshot

https://vgy.me/tiy0Tq.png

There are a lot of these small paragraphs in a big Word file, and I need to select them and copy them to a new Word File.

Sub FindTextBetweenWords()

Dim lngStart As Long
Dim lngEnd As Long
Dim newDoc As Document
Dim curDoc As Document
Set curDoc = ActiveDocument
Set newDoc = Documents.Add
curDoc.Activate
Selection.HomeKey Unit:=wdStory

With Selection.Find


.ClearFormatting
.Wrap = wdFindStop
.MatchCase = False
.Text = "References:"
If .Execute = False Then
MsgBox "'References' not found.", vbExclamation
Exit Sub
End If
lngStart = Selection.Start
Selection.Collapse Direction:=wdCollapseEnd
.Text = "Working paper No"
If .Execute = False Then
MsgBox "'Working paper No' not found.", vbExclamation
Exit Sub
End If
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
lngEnd = Selection.End
End With

newDoc.Content.Paste
curDoc.Activate
End Sub


So this thing works and does the job pretty much perfectly. But I can't make it loop for the entirety of the Document. I'll appreciate some help. Thank you in advance.
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro for copying text between two Words. Copying Certain Text From Numerous Cells using Macro Sean_Needs_Help Excel 3 11-08-2016 04:39 PM
Extracting multiple words from one cell into individual rows while copying all other data randyaserve Excel Programming 4 10-05-2015 09:52 AM
Copying words without initial word space bertietheblue Word 2 11-03-2013 04:46 PM
Macro for copying text between two Words. Macro for Copying Charts to Powerpoint bremen22 Excel Programming 1 10-01-2013 03:27 PM
Macro for replacing, copying and undoing. vthomeschoolmom Word VBA 1 12-05-2012 07:41 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:23 PM.


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