A
Ancient Brit
I have two documents - source and target. I need to copy sections from the
source document to the target document, excluding the section break but
including formatted text, tables, embedded graphics, etc. That much I have
working. I ended up using the clipboard for simplicity (even though I know
it's not the best route).
The section breaks are to be excluded in order to preserve existing
headers/footers, margins, and other page information in the target document.
We want to preserve as much as possible existing formatting from the source
docs.
However, in some cases a section in the source document consists of a
numbered heading and a continuous section break on the same line, with NO
pilcrow/paragraph mark between the two.
So when I exclude the section break, I don't get paragraph formatting for
that section.
For a reasonably well-formed source document there is at least a paragraph
mark before each section break, but there appear to be a set of rogue
documents that don't, and I need to cater for them. They could run into the
hundreds. The numbers of sections might also run into the hundreds.
I appear to be able to identify easily enough when a selected range ends in
something other than a carriage return - I check for the last character in
the range being ASCII(13).
What I'm stumped on is how to add in a necessary carriage return at the end
of the range so that the paragraph formatting is carried over to the target
document. Simplistic appending of a CHR$(13) to the range produces a mismatch
error so that's a dead end.
Anyone any ideas? Here's some rough code that I have working so far (for
obscure reasons I need to exclude the first section so the loop begins at 2,
and I've left out a bunch of other irrelevant code for clarity):
Set M_SourceDoc = ActiveDocument 'Target already open; user has opened
Source doc
For M_Loop = 2 To M_SourceDoc.Sections.Count
Set M_InitialRange = M_SourceDoc.Sections(M_Loop).Range
M_InitialRange.SetRange Start:=M_InitialRange.Start,
End:=M_InitialRange.End - 1
M_InitialRange.Copy
Documents(M_TargetDoc).Activate
Selection.Paste
...other bits followed by refocus to M_SourceDoc
Next M_Loop
Grateful for any pointers. I had wondered about possibly inserting a
carriage return into the source document when such sections arise but I'm not
keen to make changes to the source if at all possible.
Best,
Peter
source document to the target document, excluding the section break but
including formatted text, tables, embedded graphics, etc. That much I have
working. I ended up using the clipboard for simplicity (even though I know
it's not the best route).
The section breaks are to be excluded in order to preserve existing
headers/footers, margins, and other page information in the target document.
We want to preserve as much as possible existing formatting from the source
docs.
However, in some cases a section in the source document consists of a
numbered heading and a continuous section break on the same line, with NO
pilcrow/paragraph mark between the two.
So when I exclude the section break, I don't get paragraph formatting for
that section.
For a reasonably well-formed source document there is at least a paragraph
mark before each section break, but there appear to be a set of rogue
documents that don't, and I need to cater for them. They could run into the
hundreds. The numbers of sections might also run into the hundreds.
I appear to be able to identify easily enough when a selected range ends in
something other than a carriage return - I check for the last character in
the range being ASCII(13).
What I'm stumped on is how to add in a necessary carriage return at the end
of the range so that the paragraph formatting is carried over to the target
document. Simplistic appending of a CHR$(13) to the range produces a mismatch
error so that's a dead end.
Anyone any ideas? Here's some rough code that I have working so far (for
obscure reasons I need to exclude the first section so the loop begins at 2,
and I've left out a bunch of other irrelevant code for clarity):
Set M_SourceDoc = ActiveDocument 'Target already open; user has opened
Source doc
For M_Loop = 2 To M_SourceDoc.Sections.Count
Set M_InitialRange = M_SourceDoc.Sections(M_Loop).Range
M_InitialRange.SetRange Start:=M_InitialRange.Start,
End:=M_InitialRange.End - 1
M_InitialRange.Copy
Documents(M_TargetDoc).Activate
Selection.Paste
...other bits followed by refocus to M_SourceDoc
Next M_Loop
Grateful for any pointers. I had wondered about possibly inserting a
carriage return into the source document when such sections arise but I'm not
keen to make changes to the source if at all possible.
Best,
Peter