Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

selecting text

Status
Not open for further replies.

Dee0612

Technical User
May 2, 2005
17
GB
I have a small macro I have written to take data from excel to populate word and have a slight problem. Here is a sample of the way I am doing it:

Code:
wrd.ChangeFileOpenDirectory _
"\\BTBEAPDAT01\DATA_BEACON_HOUSE\NCC\Tier3 RP|Damian Templates"
wrd.Documents.Open FileName:="T66 TV Payment Letter.doc", ReadOnly:=True, AddToRecentFiles:=False

wordarray = Array(add1, add2, add3, add4, add5, blank, Pol1, yourref, OurRef, cudate, Salutation, para1, para2, para3, para4, para5, para6, para7, para8, para9, para10, name, position)

wrd.ActiveDocument.Fields(1).Select
    With wrd.Selection
    .InsertAfter Text:=addressee
    End With

For wrdroutine = 0 To 21
        wrd.Selection.NextField.Select
            With wrd.Selection
            .InsertAfter Text:=wordarray(wrdroutine)
            End With

    Next

my problem is that there are 10 possible paragraphs that I have and this code inserts them all.

What I want to be able to do is input only paragraphs if they are sleected to be input on excel. I have input check boxes so the use can select if theyw ant that paragraph input.

I have the selected paragraphs highlighted in excel like this:

Paragraphs used :
2 TRUE
3 TRUE
4 FALSE
5 TRUE
6 TRUE
7 TRUE
8 TRUE
9 FALSE
10 TRUE

What I want to do is get the VB to recognise if a paragraph is not to be used and then so for the above the wordarray would be like this:

wordarray = Array(add1, add2, add3, add4, add5, blank, Pol1, yourref, OurRef, cudate, Salutation, para1, para3, para4, para5, para6, para7, para8, para10, name, position, blank, blank)

So it would omit para2 & para10 and instead leave the last 2 fields blank.

Can this be done?

many thanks

 
Code:
For wrdroutine = 0 To 21
        wrd.Selection.NextField.Select
            With wrd.Selection
            .InsertAfter Text:=wordarray(wrdroutine)
            End With

    Next

The For..Next loop will increment wrdroutine from 0 to 21. Afte rall...you are in fact telling it to do so. So wordarray(wrdroutine) will go wordarray(0), wordarray(1), wordarray(2)....and so on. So, yeah it will do 'em all.
wordarray = Array(add1, add2, add3, add4, add5, blank, Pol1, yourref, OurRef, cudate, Salutation, para1, para3, para4, para5, para6, para7, para8, para10, name, position, blank, blank)

So it would omit para2 & para10 and instead leave the last 2 fields blank.
I am pretty sure what you want to get done can be done. It is a matter of logic and setting some sort of identifer. However, I am having trouble figuring out your logic. Why is it omiting para2 and para10 again?

Gerry
 
thanks for the reply Gerry,

sometimes some paragraphs are not relevant, for example, in the letter it is going to a customer concerning a policy they have with our company. If their policy does not have certain elements built into the policy for example life cover, the paragraph about life cover will not be applicable and does not need included in the letter. So sometimes we need to use all the paragraphs and sometimes we need only use 3 paragraphs.

The problem as you can see, is that there are quite a few possibilities the array can be, sometimes I need only para7, 8 & 9 and other times I may need para 1, 3, 7 & 10. There are about 50 different possibilities the array can be and I need an easy way to determine what the array should be!

thanks for your help on this!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top