We help IT Professionals succeed at work.

paste at end of section

Kaps_68
Kaps_68 asked
on
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

Kaps
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

new_table.Range.Copy

'paste the table

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










Next j

Open in new window

Comment
Watch Question

Top Expert 2009

Commented:
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

Commented:
If Section 2 is the last section, then go to the end of the document instead of to Section 3.
Retired
Top Expert 2012
Commented:
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
rng.Paste

Open in new window

Top Expert 2009
Commented:

Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst, Count:=3, Name:=""
   Selection.Find.ClearFormatting
   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

Commented:
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