Excel中有简单的VBA宏(2003)。它查看单元格A $ N和B $ N,并将Word文档文本从B $ N替换为A $ N。VBA宏:Excel到Word文本替换
Sub Макрос1()
Dim pathh As String, i As Integer
pathh = "c:\1.doc"
Dim pathhi As String
Dim from_text As String, to_text As String
Dim WA As Object, WD As Object
Set WA = CreateObject("Word.Application")
WA.Documents.Open (pathh)
WA.Visible = True
For oCell = 1 To 150
from_text = Range("B" + CStr(oCell)).Value
to_text = Range("A" + CStr(oCell)).Value
With WA
.Activate
With .Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = from_text
.Replacement.Text = to_text
.Execute Replace:=wdReplaceAll
End With
End With
Next
End Sub
问题:在Word文档中这个脚本只能选择文本,但不要替换。没有建议?
你有我的尺寸和使用oCell而不是 –