We help IT Professionals succeed at work.

paste at end of section

Kaps_68 asked
I want to know how to paste a table at the end of a particular section in Word e.g at the end of Section 2. I was thinking along the lines below Bookmarks("\Section 2"). However it isn't working.Any thoughts ? thanks

no_of_docs_to_add = UBound(third_Party_file_names_no_ext)

For j = 0 To no_of_docs_to_add

Set wrd_Next_Section = wrdApp.Documents.Open(third_Party_file_Names(j))

'identify the table
Set new_table = wrd_Next_Section.Tables(1)

Options.PasteFormatBetweenDocuments = 0
Options.PasteFormatBetweenStyledDocuments = 0

'copy over the document


'paste the table

wrd_Main_Doc.Bookmarks("\Section 2").Range.PasteAndFormat (wdFormatOriginalFormatting)

Next j

Open in new window

Watch Question

Top Expert 2009

This recorded macro will do the job (I have a table saved as a Building Block -- for pre-Word 2007, it was AutoText).  It goes to Section 3, then back one space, then pastes the table from Building Blocks.  Tidy it up as needed for your situation.
Top Expert 2009

If Section 2 is the last section, then go to the end of the document instead of to Section 3.
Top Expert 2012
There is a built-in bookmark called "\Section" which covers the range of the section containing the current Selection.
There aren't any for individual sections.

Do it like this:

Dim rng As Range

Set rng = wrd_Main_Doc.Sections(2).Range
rng.Collapse wdCollapseEnd
rng.Move wdCharacter, -1

Open in new window

Top Expert 2009

Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst, Count:=3, Name:=""
   With Selection.Find
      .Forward = True
      .Wrap = wdFindAsk
   End With
   Selection.MoveLeft Unit:=wdCharacter, Count:=1
   ActiveDocument.AttachedTemplate.BuildingBlockEntries("Appointment Info"). _
      Insert Where:=Selection.Range, RichText:=True

Open in new window

Top Expert 2009

It isn't clear from your code where the table to paste comes from -- if it has a standard format, it can be saved as AutoText or a Building Block