Tìm/ Thay thế dữ liệu trong Word bằng VBA excel áp dụng ở cả header và footer

Liên hệ QC

lambaonguyen

Thành viên mới
Tham gia
7/12/10
Bài viết
20
Được thích
5
Xin chào!.
Hiện tại mình có viết 1 đoạn code đơn giản để Thay thế Giá trị dữ liệu từ Excel vào Word.
Tuy Nhiên, hiện tại code này không thực hiện được trong phần nội dung header và Footer của Word. Rất mong được hỗ trợ.
Sub Replace_Word_Excel()
Dim Rws As Byte
'optimize macro
Application.ScreenUpdating = False
Application.EnableEvents = False
'Define the end rows to circulate

Range("B1").Select
Rws = Range(Selection, Selection.End(xlDown)).Count
'word execution
On Error Resume Next
With CreateObject("Word.Application") 'Open word
.Visible = True
file = [a1]
Doc = .documents.Open(ThisWorkbook.Path & "\" & file & ".docx")
.documents(ThisWorkbook.Path & "\" & file & ".docx").SaveAs Filename:=ThisWorkbook.Path & "\" & Cells(2, 2) & ".docx"
For i = 3 To Rws 'Run Cells replacement

a = Range("B" & i).Value

.Selection.Replace a, , , , , , , , , Sheets("Replacedlist").Range("C" & i).Value, 2 'Replace word from B by C value

Next

.documents(ThisWorkbook.Path & "\" & Cells(2, 2) & ".docx").Close (True)

.Quit

End With

End Sub
 
Web KT

Bài viết mới nhất

Back
Top Bottom