Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-09-2014, 08:55 PM
gmayor's Avatar
gmayor gmayor is offline Copy from a huge document Windows 7 64bit Copy from a huge document Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

If the sample document is truly representative then the following two macros will resolve the issue. The first will add sectionbreaks before each Heading 1 Styled paragraph and is a one time process. The second will copy the section you select from the index to the clipboard.

Note: If you are browsing the document want to select the section the cursor is in you will have to remove the +1 from the line:

lngSect = Selection.Information(wdActiveEndSectionNumber) + 1

This is because the index hyperlinks select the end of the previous section before the section break. It is not really worth bookmarking the headings and changing all the hyperlinks.

You could create a second macro with the change to provide both options.

Check it works as required before saving the changes to your document.

If you don't know what to do with the listings see http://www.gmayor.com/installing_macro.htm


Code:
Sub Macro1()
Dim opara As Paragraph
Dim orng As Range
    For Each opara In ActiveDocument.Paragraphs
        If opara.Style = "Heading 1" Then
            Set orng = opara.Range
            orng.Collapse wdCollapseStart
            orng.InsertBreak wdSectionBreakContinuous
        End If
    Next opara
End Sub

Sub SelectAndCopySection()
Dim orng As Range
Dim lngSect As Long
    lngSect = Selection.Information(wdActiveEndSectionNumber) + 1
    Set orng = ActiveDocument.Sections(lngSect).Range
    orng.End = orng.End - 1
    orng.Select
End Sub

__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #2  
Old 09-10-2014, 12:25 PM
freepapermate freepapermate is offline Copy from a huge document Windows 8 Copy from a huge document Office 2007
Novice
Copy from a huge document
 
Join Date: Sep 2014
Posts: 7
freepapermate is on a distinguished road
Default

Graham,

Thanks for the reply.

I was able to install the macros in the document. I see that the code works but it only works if I run it when I am in that specific heading. For example, if I want to copy the text under Heading 5 then I have to go to Heading 5 in the document (which could be in page 7) and then run the macro.

But instead can the code be tweaked so that I can copy the text under Heading 5 from the index page itself instead of having to scroll down to heading 5?
Reply With Quote
Reply

Tags
copy paste, word 2007

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy webcontent to a document elmnas Word VBA 1 07-15-2014 10:08 PM
Copy from a huge document Copy only Tables of a Document Loretti Word 1 11-12-2012 03:35 PM
Copy from a huge document Copy from one word document to another no identical gmurphy Word 3 09-07-2011 04:28 AM
Copy from a huge document How to get rid of Huge Gaps in my 300 pages Document? SpaceMuppet Word 7 05-04-2011 12:26 PM
Copy from a huge document WORD 2003 Need help splitting a HUGE Document dlawson Word 4 04-14-2009 12:22 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:02 AM.


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