Copy body of Letter

  • Thread starter Doug Robbins - Word MVP
  • Start date
D

Doug Robbins - Word MVP

The idea is that you use the white space to describe your problem/what it is
that you want to do.

This may or may not be it

Dim body as Range
Set body = ActiveDocument.Range
body.End = body.End - 1
body.Copy

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
B

Brian McGuigan

I don't think that solves the problem as I do not want to capture the whole
body of the document - just the bit after 'Dear Doug' for example and before
'Regards Brian'.
Thus omitting any address, signature, job title and so on. I just do not
seem to be able to find out how to locate a charcter string that will define
the start and end of the Range I require. I can insert a non-printing
special character to mark the end and beginning of the range when I create
the document from the Template, but the User may subsequently edit the
document changing their location.

Regards Brian
 
D

Doug Robbins - Word MVP

Does help if you explain what it is that you want to do.

Dim Body As Range
Set Body = ActiveDocument.Range
Body.Start = Body.Start + InStr(Body, "Dear")
Body.Start = Body.Start + Len(Body.Paragraphs(1).Range) - 1
Body.End = Body.Start + InStr(Body, "Regards") - 1
Body.Select


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
B

Brian McGuigan

Yes that helps. I could not work out how to define the Start and end of the
Range. I'll be using special non-printing characters to mark the beginning
and end, as my Users may choose different start and ends, but I can take it
from here.

Many Thanks
Brian McGuigan
 
B

Brian McGuigan

Brian McGuigan said:
Yes that helps. I could not work out how to define the Start and end of the
Range. I'll be using special non-printing characters to mark the beginning
and end, as my Users may choose different start and ends, but I can take it
from here.

Many Thanks
Brian McGuigan
 
B

Brian McGuigan

Here is the final solution I used.

In the end I defined two Bookmaks in all my Templates called "BodyStart" and
"BodyEnd". I then could find the start and end of the Range to be copied as
follows:

'Find where the DocumentBody starts
'==================================
Set DocumentBody = WordDocument.Range

On Error Resume Next 'in case Bookmark does not exist
BodyStart _
= WordApplication.ActiveDocument.Bookmarks("BodyStart").Start
On Error GoTo 0

' If There is a Bookmark start the range at the Bookmark
If (BodyStart > 0) Then
DocumentBody.Start = BodyStart
Else
'If there is no Bookmark then locate Keyword
BodyStart = InStr(DocumentBody, g_SalutationUsed & " ")
If (BodyStart > 0) Then
'If Keyword found position BodyStart to beginning of next Line
DocumentBody.Start = BodyStart
'Convert DocumentBody to Text so that MERGEFIELDS will show
in full length
DocumentBodyText = DocumentBody
DocumentBody.Start = DocumentBody.Start +
InStr(DocumentBodyText, Chr(13)) + 2
Else
'Include beginning of Document
DocumentBody.Start = 0
End If
End If

'Find where the DocumentBody ends
'================================
On Error Resume Next 'in case Bookmark does not exist
BodyEnd _
= WordApplication.ActiveDocument.Bookmarks("BodyEnd").Start
On Error GoTo 0

' If There is a Bookmark end the range at the Bookmark
If (BodyEnd > 0) Then
DocumentBody.End = BodyEnd
Else
'If there is no Bookmark then locate Keyword
DocumentBodyText = DocumentBody 'Convert DocumentBody to Text
'so that any MERGEFIELDS will
show full length
BodyEnd = InStr(DocumentBodyText, g_YoursUsed)

'If Keyword found position BodyEnd to start of current Line
If (BodyEnd > 0) Then
DocumentBody.End = BodyStart + BodyEnd - 2
Else
'Include end of Document
End If
End If
 

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