Can you help out with my formatting problem?

P

Patrick Finucane

Bear with me, there is a reason for what I need to do. I have a
document template with mail merge fields. This form will be mail merged
from Access and saved. A situation may come up where I need to grab the
data between the salutation and the Sincerely and paste it into the new
document. This is my first attempt at working with Word VBA...I'm
hoping you can spot what I need to do.

Ex of the document:
Joe Blow
123 Somewhere St
Anywhere USA 12345<BodyTextStart Bookmark>

blah blah blah
blah blah blah

<BodyTextEnd Bookmark>Sincerely,
Jane Doe

The lines of blah, blah, blah are the body text. I put in a couple of
bulleted items and bolded a couple of workds and ran the tollowing
code. It WORKS!!!!...except the bolding gets lost and and bullets are
gone...just the text. Can you help out?

Sub testDocument()
On Error GoTo ErrorHandler
Dim lngStart As Long
Dim lngEnd As Long
Dim aRange As Range

'bookmark where the body of the letter will start and end
lngStart = ActiveDocument.Bookmarks("BodyTextStart").Start
lngEnd = ActiveDocument.Bookmarks("BodyTextEnd").Start - 1

'define the range
Set aRange = ActiveDocument.Range(Start:=lngStart, End:=lngEnd)

'I set a range to BodyTextEnd and did an edit paste but
'it overwrote the Sincerely stuff. I need to insert, not paste over
'aRange.Select
'aRange.Copy
'aRange.Paste

'the following line does not work or compile but from what
'I read, PasteSpecial does what I want this routine to do (I think).
'aRange.InsertAfter aRange.PasteSpecial DataType:=wdPasteText

'these are close but no cigar..the formatting of bold and bullets
not there
'aRange.InsertAfter aRange.FormattedText.Duplicate
'or this
'aRange.InsertAfter aRange.FormattedText

MsgBox "Done"

Exit_Test:
Exit Sub

ErrorHandler: ' Error-handling routine.
If Err.Number = 5941 Then
MsgBox "One of the bookmarks does not exit"
Else
MsgBox Err.Description
End If
Resume Exit_Test
End Sub
 
D

Doug Robbins - Word MVP

Identical Post in microsoft.public.word.word97vba newsgroup.

Please do not spam the newsgroups by posting the same question separately to
multiple newsgroups. Rather, if you are not sure which is the most
appropriate newsgroup, insert the names of those which you think might be
appropriate into the header of a single message. When you do that, an
answer in one newsgroup will automatically appear in all of the newsgroups
to which you posted. That will make it easier for you to find responses and
can also reduce the possibility of someone developing an answer to a
question that has already been answered.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

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