'Chuong trinh tao quyet dinh phan cong
Sub TBNhanuythac()
'Khai bao bien
Dim wapp As Word.Application
Dim wdoc As Word.Document
Dim numOfRow, numOfColumn, iRow, iColumn As Long
'Gan gia tri cho cac bien
Set wapp = CreateObject("word.application")
wapp.Visible = True
With ThisWorkbook.Sheets("Chu dong")
numOfRow = Excel.WorksheetFunction.CountA(.Columns(3)) - 1
numOfColumn = Excel.WorksheetFunction.CountA(.Rows(2))
For iRow = 1 To numOfRow Step 1
Set wdoc = wapp.Documents.Open(ThisWorkbook.Path & "\Chu dong\Ho so thi hanh an dan su chu dong.docx")
For iColumn = 1 To numOfColumn Step 1
wdoc.Content.Find.Execute _
findtext:=.Cells(2, iColumn + 1), _
replacewith:=.Cells(iRow + 2, iColumn + 1), _
Replace:=wdReplaceAll
Next
wdoc.SaveAs2 Filename:=ThisWorkbook.Path & "\Luu tru\Chu dong\" & _
.Cells(iRow + 2, 2) & " - Ho so thi hanh an dan su chu dong" & ".docx"
wdoc.Close
Next
wapp.Quit
Set wdoc = Nothing
MsgBox "Da tao xong ho so chu dong", vbInformation, "Tao ho so THADS"
End With
End Sub