Gửi thầy, mình soạn đoạn code sau để điền dòng 2 từ bảng excel vào file word. File excel có 9 cột, kết quả là vẫn tạo ra file word Hop dong 1.docx, nhưng dữ liệu không được thay thế. Nhờ thầy xem giúp:
Sub test()
Dim num_of_colmn As Long
Dim TestHD1 As Object
Dim j As Long
Dim t As Object
num_of_column = 9
With CreateObject("word.application")
.Visible = True
Set TestHD1 = .documents.Open("D:\Soan thao\TestHD1.docx")
Set t = TestHD1.Content
For j = 1 To num_of_column
t.Find.Execute _
FindText:=Sheet1.Cells(1, j).Value, ReplaceWith:=Sheet1.Cells(2, j).Value, Replace:=wdreplaceall
Next
TestHD1.SaveAs Filename:=ThisWorkbook.Path & Application.PathSeparator & "Hop dong 1.docx"
.Quit
End With
Set t = Nothing
Set TestHD1 = Nothing
End Sub