Currently I am using a for loop to lay down 4 rounds of data, I was hoping to have it replace all that are corresponding to the current word template, but doing this all in excel VBA Unfortunately the code that I am not using is no working and the wdReplaceAll = Empty.
I've tried resetting parameters and even having .Execute Replace:=wdReplaceAll changed to .Execute Replace:=1. But Nothing in my word document is being replaced
Dim WordApp As Object
Dim DocFileName As String
Set WordApp = CreateObject("Word.Application")
DocFileName = ActiveWorkbook.Path & "\Word\TCAP Update.docx"
WordApp.Documents.Open DocFileName
For i = 1 To TCAPCount
Summary(i) = ActiveCell.Offset(0, -1).Value
Key(i) = ActiveCell.Offset(0, -2).Value
Updated(i) = Format(ActiveCell.Offset(0, 1).Value, "MM/DD/YYYY")
Cells.Find(what:="NEAR DATE", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=True).Activate
ColorInd = ActiveCell.DisplayFormat.Interior.Color
ActiveCell.Offset(0, 1).Select
Do Until ActiveCell.Value <> "NEAR DATE" And ActiveCell.DisplayFormat.Interior.Color = ColorInd
ActiveCell.Offset(0, 1).Select
Loop
ActualDate(i) = Format(ActiveCell.Value, "MM/DD/YYYY")
ActualDateNam(i) = Range(Split(ActiveCell(1).Address(1, 0), "$")(0) & "1").Value
Range(SEMCol & ActiveCell.Row).Select
Do
ActiveCell.Offset(1, 0).Select
If ActiveCell.EntireRow.Hidden = True Then
'keep looking
Else
Exit Do
End If
Loop
Next i
If TCAPCount > 1 Then
MsgBox "Please take this time to create " & TCAPCount & " extra TCAP Templates for " & SEM
WordApp.Visible = True
MsgBox "When you are ready to proceed please select OK"
End If
For i = 1 To TCAPCount
With WordApp.Selection.Find
.Text = "Key " & (i)
.Replacement.Text = Key(i)
.Execute Replace:=wdReplaceAll
.Text = "Summary " & (i)
.Replacement.Text = Summary(i)
.Execute Replace:=wdReplaceAll
.Text = "ActualDate " & (i)
.Replacement.Text = ActualDate(i)
.Execute Replace:=wdReplaceAll
.Text = "ActualDateNam " & (i)
.Replacement.Text = ActualDateNam(i)
.Execute Replace:=wdReplaceAll
.Text = "Updated " & (i)
.Replacement.Text = Updated(i)
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Next i
I am hoping to replace Key 1 | Summary 1 ActualDateNam 1– ActualDate 1 Last Update: Updated 1 Key 2 | Summary 2 ActualDateNam 2– ActualDate 2 Last Update: Updated 2 Key 3 | Summary 3 ActualDateNam 3– ActualDate 3 Last Update: Updated 3 Key 4 | Summary 4 ActualDateNam 4– ActualDate 4 Last Update: Updated 4
with it's corresponding data ie i=1 and Key (i) = "Apples", then Key 1 will be replaced as "Apples".