binh123456789
Thành viên thường trực
![](/diendan/data/PhoToDanhHieu/gold.gif)
![](/diendan/data/PhoToDanhHieu/gold.gif)
![](/diendan/data/PhoToDanhHieu/gold.gif)
![](/diendan/data/PhoToDanhHieu/gold.gif)
- Tham gia
- 13/5/15
- Bài viết
- 267
- Được thích
- 12
Sub test()
Dim num_of_cust As Long
Dim num_of_column As Long
Dim i As Long, j As Long
Dim template As Object
Dim t As Object
num_of_column = 3
num_of_cust = Sheet1.Cells(Rows.Count, "A").End(xlUp).Row - 1
With CreateObject("word.application")
.Visible = True
For i = 1 To num_of_cust
Set template = .Documents.Open("C:\Users\Admin\Desktop\template.docx")
Set t = template.Content
For j = 1 To num_of_column
t.Find.Execute _
FindText:=Sheet1.Cells(1, j).Value, _
ReplaceWith:=Sheet1.Cells(i + 1, j).Value, _
Replace:=wdReplaceAll
Next
template.SaveAs Filename:=ThisWorkbook.Path & Application.PathSeparator & i & "dekt.docx"
Next
.Quit
End With
Set t = Nothing
Set template = Nothing
End Sub
Dim num_of_cust As Long
Dim num_of_column As Long
Dim i As Long, j As Long
Dim template As Object
Dim t As Object
num_of_column = 3
num_of_cust = Sheet1.Cells(Rows.Count, "A").End(xlUp).Row - 1
With CreateObject("word.application")
.Visible = True
For i = 1 To num_of_cust
Set template = .Documents.Open("C:\Users\Admin\Desktop\template.docx")
Set t = template.Content
For j = 1 To num_of_column
t.Find.Execute _
FindText:=Sheet1.Cells(1, j).Value, _
ReplaceWith:=Sheet1.Cells(i + 1, j).Value, _
Replace:=wdReplaceAll
Next
template.SaveAs Filename:=ThisWorkbook.Path & Application.PathSeparator & i & "dekt.docx"
Next
.Quit
End With
Set t = Nothing
Set template = Nothing
End Sub