Robustly fetching the range between two field codes.

R

Robin Tucker

Say, for example, I have a single page looking something like this:


<<SECTION_START>>
------------------------------------------------------------
| Database ID | Asset Title
|
------------------------------------------------------------
| <<ASSET_ID>> | <<ASSET_NAME>> |
------------------------------------------------------------
<<SECTION_END>>


How is it possible to remove the field codes <<SECTION_START>> and
<<SECTION_END>>, without leaving blank lines above and below, so that when I
perform a directory merge I end up with one big table, rather than something
like the following:

------------------------------------------------------------
| Database ID | Asset Title
|
------------------------------------------------------------

------------------------------------------------------------
| 10234 | Primary Crusher |
------------------------------------------------------------

------------------------------------------------------------
| 10235 | Secondary Crusher |
------------------------------------------------------------

What I want, is something that looks like this:

------------------------------------------------------------
| Database ID | Asset Title
|
------------------------------------------------------------
| 10234 | Primary Crusher |
------------------------------------------------------------
| 10235 | Secondary Crusher |
------------------------------------------------------------

To enlarge a little more, I have report "templates", within which the user
can embed "SECTION_START" and "SECTION_END" tags. My code then goes through
the template, splitting it into separate documents (everything between
SECTION_START and SECTION_END). These documents are then mail-merged with
the data source, before being re-combined into the finished report. This
allows me to do a main report section, on a given set of records and then a
summary section on another, different set of records. At present I'm
finding the range between the tags like so:

' The indices of the start and end section tags (index within the fields
collection for the document)

Dim theSectionStartIndex, theSectionEndIndex as integer

...
... find the section start and end tag indices
...

theRange = m_LoadedDocument.Fields.Item(theSectionStartIndex).Result
theRange.Collapse(Word.WdCollapseDirection.wdCollapseStart)
theRange.MoveStart(Word.WdUnits.wdCharacter, -1)

theRange.End =
m_LoadedDocument.Fields.Item(theSectionEndIndex).Result.End
theRange.MoveEnd(Word.WdUnits.wdCharacter, 1)

But when merged, this range results in the split table above, rather than a
combined one.

Thanks for any hints you can give me about this.




Robin
 
P

Peter Jamieson

Not sure what the solution is, but...

Could it be that
a. you end p pasting the range into a new document in order to perform
the merge
b. you do not replace the paragraph mark that exists in any new blank
document, pushing it to the end instead?

But FWIW I did not really understand the code as I thought that you
needed to select the end of the Section-start field, then move a
character or two twoards the end of the document, then extend to the
start of the section_end field, then move the end back a character or
two, then cut/paste that lot into a document to be merged - e.g.,
perhaps more like

theRange = m_LoadedDocument.Fields.Item(theSectionStartIndex).Result
theRange.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
theRange.MoveStart(Word.WdUnits.wdCharacter, 2)

theRange.End =
m_LoadedDocument.Fields.Item(theSectionEndIndex).Result.Start
theRange.MoveEnd(Word.WdUnits.wdCharacter, -1)

(or -2)

But I would also expect the behaviour to be dependent on what is visible
in the document (fields, perhaps para. marks etc.).

Best I can do right now,

Peter Jamieson
 

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