tags:

views:

335

answers:

2

Hello all,

I'm putting together a template in Word, using a form for the user to fill in to then populate some of the document.

The bit I'm currently stuck on is at the end of the document, where the cc's are listed.

The form has a multiline text box into which the user puts in their cc's, one per line.

I then want to add to the end of the document the contents of the text box, but in the right format. Specifically, it should look like:

cc:    First CC contact
       Second CC contact
       so on and so forth

I attempted to do this using 2 bookmarks, so my code currently is:

' If 'CC' box has content, add it
If doc_CC.TextLength > 0 Then
    .Bookmarks("CC").Range.Text = vbCr + "cc:"
    .Bookmarks("CCs").Range.Paragraphs.Indent
    .Bookmarks("CCs").Range.Text = doc_CC + vbCr
End If

However, when this is run, on the page it looks like:

       cc:     first contact
       second contact
       and so on

Realise that the 2 bookmark method is a bit messy but it seemed like a good idea at the time - obviously this is not the case! Have done some searching for a way to do it with Split but am not making much progress down this path - suspect I'm googling for the wrong thing.

How do I do this so that the formatting is as desired? Any help is greatly appreciated.

A: 

Try inserting a tab character? + Chr(9) or even + vbTab may work.

tbs
I have tried using the tab character instead of the paragraph indent. The first line looks fine but subsequent lines are not indented (which was a suprise - it did not behave the same as if you did it manually typing into a document - if you tab, then hit enter, your next line will be tabbed. When adding the tab in the vba, this is not the case. The next line will default back to the left margin.
Matt
Why not insert a tab for each line?
tbs
A: 

Have found a work around which, while doesn't answer the actual question of how to do it, does produce a result to the same effect.

Have used a 2 column table without no lines instead with contents of a1 being "cc:" and contents of a2 being whatever was entered into the multiline text box. If there is nothing in the text box, then the table is deleted.

I'll keep on eye on this question though so if some one does have the proper answer I can mark it accordingly.

Matt

related questions