PDA

View Full Version : Copy and pasting to new pages/TOC help



Surfwave88
06-24-2008, 10:15 AM
I'm a beginner and this is probably really easy but I was trying to make a code that will copy what you have selected in a word document and paste it on a new page in the same word document. I keep only getting it to paste at the end of the current page.

Also in word 2007 you can create a table of contents based on how you categorize headings and sub headings, but is there any way where you could make a table of contents first and then run a macro that would copy each section in the table of contents and paste the headings in the word document and also format it the correct way?

lucas
06-24-2008, 12:44 PM
Inserts a new page right after the selection.....you don't specify.
Option Explicit
Sub CopyCurrentSelection()
With Selection
.Copy
.Collapse Direction:=wdCollapseEnd
.InsertBreak Type:=wdPageBreak
.Paste
.InsertBreak Type:=wdPageBreak
End With
End Sub

fumei
06-24-2008, 06:41 PM
As for your second paragraph...no. That is not how it works.

A ToC is generated by looking for the existence of specific styles in the document.

For example:

IF there is text with Heading 1 style, then that text is a first level item in the ToC.

IF there is text with Heading 2 style, then that text is a second level item in the ToC.

If you generated a ToC (or tried to), and there are NO paragraphs with the styles Word is using to generate the ToC, then...there is nothing in the ToC. It would be blank, no items.

In other words:

" is there any way where you could make a table of contents first and then run a macro that would copy each section in the table of contents and paste the headings in the word document and also format it the correct way?"

No.

However...you should look at using Outlines. This pretty much does what you seem to be asking about.

Surfwave88
06-26-2008, 08:23 AM
Thanks so much. I didn't even realize there was an outline maker in Word, thats exactly what I was trying to make. Thanks again to both of you.