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:
thanks for the reply, I am unable to upload the excel doc and unbale to compress it to upload as my company have limited what we can do on our computers!
I have uploaded the MS word doc, here is the full code I am using in excel:
Code:
Sub Printletter()
Application.ScreenUpdating = False
Pol1 = Range("C4")
TVamount = Range("E4")
Claimno = Range("G4")
PSO = Range("I4")
phsurname = Range("C16")
phfirstname = Range("C18")
dob = Range("C20")
OurRef = Range("E14")
yourref = Range("E16")
othersal = Range("E18")
scheme = Range("E20")
add1 = Range("E22")
add2 = Range("E23")
add3 = Range("E24")
add4 = Range("E25")
ch = Range("C30")
percentage = Range("E30")
Sheets("Signed").Select
Signed = Range("C1")
Position = Range("D1")
trans = Range("H3")
Name = Range("H9")
cudate = Range("G16")
Sheets("Output").Select
addressee = Range("A1")
'paras to be used:
para1 = Range("M66")
para2 = Range("M67")
para3 = Range("M68")
para4 = Range("M69")
para5 = Range("M70")
para6 = Range("M71")
para7 = Range("M72")
para8 = Range("M73")
para9 = Range("M74")
para10 = Range("M75")
'On Error GoTo NoWord
Set wrd = GetObject(, "Word.Application")
GoTo continue
NoWord:
MsgBox ("Please Open MS Word application & try again." & Chr(13) & _
"If MS Word is open the macro has encountered another problem." & Chr(13) & _
"Please try again. If the problem persists please contact Damian Reid.")
End
continue:
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(Inputtext1,
wrd.ActiveDocument.Fields(1).Select
With wrd.Selection
.InsertAfter Text:=addressee
End With
For wrdroutine = 0 To 23
Set f = wrd.Selection.NextField
wrd.Selection.NextField.Select
With wrd.Selection
.InsertAfter Text:=wordarray(wrdroutine)
End With
Next
End
End Sub
The big problem is try to ascertain which para to use, sometimes it may only para 3, 4 & 7 and others we may need paras 5, 6 & 10!
thanks
Last edited by rocket0612; Feb 21st, 2006 at 03:27 AM.
The Box Said: "You need Windows Vista or better" ... So I Installed LiNUX
seem to have conquered this after a lot of thought for anyone that is interested, inserted this once the word doc was opened and populated with the first bits of text (eg name address fields):
Code:
ROW = 64
field = 16
For rowcount = 0 To 9
ROW = ROW + 1
P = Range("L" & ROW)
If P = True Then
par = Range("M" & ROW)
Wrd.ActiveDocument.Fields(field).Select
With Wrd.Selection
.InsertAfter Text:=par
End With
field = field + 1
End If
Next
The Box Said: "You need Windows Vista or better" ... So I Installed LiNUX