Private Sub CommandButton4_Click()
Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim i As Integer
Dim theCombo As Control
Dim theTextBox800 As Control
Dim theTextBox801 As Control
Dim x As Integer
Dim y As Integer
Dim Txt1 As String
Dim Txt2 As String
Dim Txt3 As String
Dim Txt1Rplce As String
Dim Txt2Rplce As String
Dim Txt3Rplce As String
x = iAddedCount
y = 1
Set objWord = New Word.Application
objWord.DisplayAlerts = False
objWord.Visible = True
objWord.Documents.Open ActiveWorkbook.Path & "\OSR Advisory Letter3.dotm", ReadOnly:=True
objWord.Activate
objWord.Selection.Start = 1445
With objWord.ActiveDocument
.FormFields("nameTitle1").Result = titleCombo1
.FormFields("firstName1").Result = firstNameText
.FormFields("lastName1").Result = lastNameText
.FormFields("companyName1").Result = siteName
.FormFields("addressName1").Result = addressLine1
.FormFields("postCode1").Result = postCode
.FormFields("PPref1").Result = ppReference
.FormFields("nameTitle2").Result = titleCombo1
.FormFields("lastName2").Result = lastNameText
.FormFields("inspDate1").Result = DTPicker1
End With
For Each theCombo In OSRData.MultiPage1.Pages(7).Controls
If x > 0 Then
Txt1 = Me("Combo" & y).Text
Txt2 = Me("Text1" & y).Text
Txt3 = Me("Text2" & y).Text
Txt1Rplce = Replace(Txt1, vbLf, Chr(11))
Txt2Rplce = Replace(Txt2, vbLf, "")
Txt3Rplce = Replace(Txt3, vbLf, "")
objWord.Selection = Me("Combo" & y).Value 'Copies and pastes text from combobox to selection in word document
With objWord.Selection
.ParagraphFormat.Alignment = wdAlignParagraphJustify
.Font.Name = "Arial"
.Font.Size = 11
.ParagraphFormat.LeftIndent = 30 'working
.Range.ListFormat.ApplyNumberDefault
.MoveRight
.TypeParagraph
.ParagraphFormat.Alignment = wdAlignParagraphLeft
.Range.ListFormat.ApplyNumberDefault
.TypeParagraph
End With
objWord.Selection = "Observations:" & vbCr & Txt2Rplce 'Copies and pastes text from first textbox to selection in word document
With objWord.Selection
.Font.Name = "Arial"
.Font.Size = 11
.Font.Bold = True
.ParagraphFormat.LeftIndent = 30 'working
.MoveRight
.TypeParagraph
.TypeParagraph
End With
objWord.Selection = "Action(s):" & vbCr & Txt3Rplce 'Copies and pastes text from second textbox to selection in word document
With objWord.Selection
.Font.Name = "Arial"
.Font.Size = 11
.Font.Bold = True
.ParagraphFormat.LeftIndent = 30 'working
.MoveRight
.TypeParagraph
End With
End If
y = y + 1
x = x - 1
Next theCombo
End Sub