如果我理解你是正确的,你想用你的Excel文件中列出的单词替换Word文档中的单词。如果是这样,这个宏应该做的伎俩(宏的MS Word):
Function findAndReplace()
Dim xlApp As Object
Dim xlWB As Object
Dim xlWS As Object
Dim i As Integer, j As Integer
Dim lastRow As Integer
'Set Objects
Set xlApp = CreateObject("Excel.Application")
Set xlWB = xlApp.Workbooks.Open("PATH TO EXCEL FILE") 'Replace String with path to Excel File
Set xlWS = xlWB.Worksheets("Name of Worksheet") 'Replace String with your Worksheet Name
'get last row of excel file
lastRow = xlWS.UsedRange.SpecialCells(xlCellTypeLastCell).Row
'loop through all words in Word Document
For i = 1 To ThisDocument.Words.Count - 1 Step 1
'Loop through cells in Excel File
For j = 1 To lastRow Step 1
'Replace Word value in Column B of Excel File
ThisDocument.Words(i) = Replace(ThisDocument.Words(i), xlWS.Cells(j, 1).Value, xlWS.Cells(j, 2).Value)
Next j
Next i
'Close Excel and Cleanup
Set xlWS = Nothing
xlWB.Close True
Set xlWB = Nothing
xlApp.Quit
Set xlApp = Nothing
端功能
如果我明白你错了,请给我们你正在尝试做的更多细节。
您是否尝试在Excel或Word中创建VBA宏来执行此操作? –