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而不是 –