Consulting

Results 1 to 4 of 4

Thread: Copy and pasting to new pages/TOC help

  1. #1

    Copy and pasting to new pages/TOC help

    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?

  2. #2
    VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Inserts a new page right after the selection.....you don't specify.
    [VBA]Option Explicit
    Sub CopyCurrentSelection()
    With Selection
    .Copy
    .Collapse Direction:=wdCollapseEnd
    .InsertBreak Type:=wdPageBreak
    .Paste
    .InsertBreak Type:=wdPageBreak
    End With
    End Sub
    [/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    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.

  4. #4
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •