On Error GoTo errHandler
With wsRaw
lrRaw = Last(1, .Columns(1))
lcRaw = Last(2, .Rows(3))
For i = 4 To lrRaw
If bCancel = True Then GoTo ExitSub
strEmpName = .Cells(i, 2).Value
Application.ScreenUpdating = True
ws.Range("C13").Value = "Working on OT Form for """ & strEmpName & """"
Application.ScreenUpdating = False
DoEvents
strOutputFile = addFileExtension(strTemplateFile, strEmpName)
strOutputPath = strOutputLocation & strOutputFile
FileCopy strTemplatePath, strOutputPath
Set wdApp = GetObject(, "Word.application") 'gives error 429 if Word is not open
If Err = 429 Then
Set wdApp = CreateObject("Word.application") 'creates a Word application
Err.Clear
End If
wdApp.Visible = False 'True '
Set wdDoc = wdApp.Documents.Open(strOutputPath)
'With wdDoc
' .Application.WindowState = 1
' .ActiveWindow.ActivePane.View.Zoom.Percentage = 100
'End With
For j = 1 To 7 'lcRaw
strSearch = "< " & .Cells(3, j).Value & " >"
strReplace = .Cells(i, j).Value
For Each wdRng In wdDoc.StoryRanges
With wdRng.Find
.Text = strSearch
.Replacement.Text = strReplace
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
DoEvents
Next wdRng
DoEvents
Next 'lcRaw (data column)
wdDoc.Close SaveChanges:=True
Set wdRng = Nothing: Set wdDoc = Nothing
DoEvents
Next 'lrRaw (data row)
End With