Paste does not retain table format or section breaks

D

DebbiePartridge

Hi there

Wondering if anyone has any ideas what I'm doing wrong here?

I have a document with three sections, all of which contain a mix o
text in tables and outside of tables. I want to copy and paste variou
sections, sometimes one, sometimes one & three etc.

The code I have written works to a certain extent but, when pastin
text, loses the table format entirely (i.e. just pastes the text lin
after line) and changes the section breaks to page breaks.

The code is:

Sub Test3()

Dim WholeDocument As Range
Dim Bill As Range, Remuneration As Range, Narrative As Range

Set WholeDocument = Nothing
Set Bill = Nothing
Set Remuneration = Nothing
Set Narrative = Nothing

Set WholeDocument = ActiveDocument.Content

Selection.GoTo What:=wdGoToSection, Which:=wdGoToAbsolute, count:=1
ActiveDocument.Bookmarks("\section").Select
Set Bill = Selection.Range

Selection.GoTo What:=wdGoToSection, Which:=wdGoToAbsolute, count:=2
ActiveDocument.Bookmarks("\section").Select
Set Remuneration = Selection.Range

Selection.GoTo What:=wdGoToSection, Which:=wdGoToAbsolute, count:=3
ActiveDocument.Bookmarks("\section").Select
Set Narrative = Selection.Range

WholeDocument.Collapse Direction:=wdCollapseEnd

With WholeDocument
.InsertAfter (Bill)
.InsertAfter (Remuneration)
.InsertAfter (Narrative)
End With

End Sub

Any suggestions gratefully appreciated.
Many thanks
Debbi
 
D

dz

I think when you place text in a variable, it just
becomes, well, text. You might have to change your code
to do a simple copy of the range selection, and then a
regular paste. But, you would immediately need to paste
the copied text in the correct location for each range
selection.

Unfortunately, manipulating the clipboard object has the
same limitations, but you can try it...


-----Original Message-----
Hi there

Wondering if anyone has any ideas what I'm doing wrong here?

I have a document with three sections, all of which contain a mix of
text in tables and outside of tables. I want to copy and paste various
sections, sometimes one, sometimes one & three etc.

The code I have written works to a certain extent but, when pasting
text, loses the table format entirely (i.e. just pastes the text line
after line) and changes the section breaks to page breaks.

The code is:

Sub Test3()

Dim WholeDocument As Range
Dim Bill As Range, Remuneration As Range, Narrative As Range

Set WholeDocument = Nothing
Set Bill = Nothing
Set Remuneration = Nothing
Set Narrative = Nothing

Set WholeDocument = ActiveDocument.Content

Selection.GoTo What:=wdGoToSection,
Which:=wdGoToAbsolute, count:=1
ActiveDocument.Bookmarks("\section").Select
Set Bill = Selection.Range

Selection.GoTo What:=wdGoToSection,
Which:=wdGoToAbsolute, count:=2
ActiveDocument.Bookmarks("\section").Select
Set Remuneration = Selection.Range

Selection.GoTo What:=wdGoToSection,
Which:=wdGoToAbsolute, count:=3
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top