Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-08-2014, 05: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 Copy from a huge document

Hi,

I hope to get some help from here from somebody relating to Microsoft Word 2007.

I have one huge document (more than 200 pages). There are multiple bookmarks (or Headings; all are Heading 1) and these bookmarks are listed on page one of this huge document as an index and are hyperlinked to their specific section on the document. Every now and then I am required to copy the text located under one bookmark (or under one heading).

Currently, I am clicking on bookmark (or heading) on page 1 which takes me to that section on the document and I then select the text until the next bookmark (or heading)and then copy and paste to another document. This is time consuming since I have to do such copy and paste nearly 100 times a day.

Is there a way to select (or copy/paste) from the index page (the first page) where I can just choose the bookmark (or heading) and automatically the text under that bookmark (or heading) is copied until the next bookmark (or heading) without having to scroll down and select and then copy?

I would highly appreciate any help that anyone could offer.
Reply With Quote
  #2  
Old 09-08-2014, 11:40 PM
macropod's Avatar
macropod macropod is offline Copy from a huge document Windows 7 64bit Copy from a huge document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,342
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

If your document has Section breaks before these headings, it's easy enough to tell Word via VBA to copy an entire Section; otherwise the code would have to basically do as you're doing now - find the heading, scan forwards till the next heading, then copy everything from the start of the first heading to the start of the second heading. If you can clarify your document's structure, a suitable macro could be written.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 09-09-2014, 05:11 AM
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,137
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 your document doesn't have section breaks at each bookmark, it might be simpler just to add them. That could be done with a macro. Then Paul's suggestion to copy the section is easy enough to implement. Again a bit more information would be required.
__________________
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
  #4  
Old 09-09-2014, 03:23 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

Hi,

Thanks for your replies and willingness to help.

I have attached a sample document for you here. Since the document that I am working with is huge and is a bit confidential I can't share the exact same document but I have made a sample and am attaching it here. Please note that this test document only has 5 headings (or sections) but the real document has 100 such headings (or sections).

To review here is what I am looking for and I am putting the attached text document in perspective:

1. I open the attached document.
2. I am asked to just copy the text under "Heading 3" which I can then paste anywhere.
3. I should be able to able to copy whatever text is under "Heading 3" without having to scroll down to "heading 3", selecting the text and hitting control+C. If I can copy the text from the first index page itself then it would be great without having to scroll down.

How can I do that if possible? I can add section breaks if needed which is fine.

Thanks
Attached Files
File Type: docx Test document.docx (10.7 KB, 16 views)
Reply With Quote
  #5  
Old 09-09-2014, 06:22 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

I was able to get the code to select and copy between two known bookmarks which works for me. But How to do this with unknown bookmark.

I used the below code:

Dim orng As Range
Set orng = ActiveDocument.Range
orng.Start = orng.Bookmarks("BM1").Range.End
orng.End = orng.Bookmarks("BM2").Range.Start
orng.Select

How can I modify the above code so that "BM1" is what I from index?
Reply With Quote
  #6  
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,137
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
  #7  
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
  #8  
Old 09-10-2014, 12:33 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

Also the code only works if I am browsing the document and if I remove the +1 in that line of code. The code does not work from the index page.
Reply With Quote
  #9  
Old 09-10-2014, 12:39 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

I was able to get it work from the index page but it only works for text under "Heading 1" and always only selects the text under "Heading 1" even if I am in "Heading 2".
Reply With Quote
  #10  
Old 09-10-2014, 10:03 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,137
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

To run it from the hyperlink. Put the cursor in the hyperlink and run the following modified version. This will copy the section to the clipboard and return to the start position

Code:
Sub SelectAndCopySection()
Dim oRng As Range
Dim oStart As Range
Dim lngSect As Long
    Set oStart = Selection.Range
    If oStart.Hyperlinks.Count = 1 Then
        oStart.Hyperlinks(1).Follow
        lngSect = Selection.Information(wdActiveEndSectionNumber) + 1
        Set oRng = ActiveDocument.Sections(lngSect).Range
        oRng.End = oRng.End - 1
        oRng.Copy
        oStart.Select
    End If
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
  #11  
Old 09-11-2014, 08:55 AM
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

This work perfectly. The only thing I need now is to not to copy the heading text. For example, currently it also copies the text "Heading 1". How can I make it so that it only starts copying from the next line of "Heading 1".

Thanks for the help.
Reply With Quote
  #12  
Old 09-11-2014, 08:49 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,137
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

Add the line
orng.Start = orng.Paragraphs(2).Range.Start
immediately after
orng.End = orng.End - 1
__________________
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
Reply

Tags
copy paste, word 2007



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 02:13 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