楼主的写复杂了,而且估计效率不太好,试下下面这个,可以自己加上些提示方式$xls=ObjGet(@ScriptDir&"\data.xls")
With $xls.activesheet
$rng=.range("a1",.cells(1,.columns.count).end(1))
EndWith
$word=ObjCreate("word.application")
$word.visible=False ;想看到替换过程的话,把这里改成true
For $r In $rng
If StringLen($r.value)>0 Then
$doc=$word.documents.open(@ScriptDir&"\word.doc")
With $doc
.parent.selection.find.execute($r.value, Default, Default, Default, Default, Default, Default, Default, Default, $r.offset(1).value, 2)
.saveas(@ScriptDir&""&$r.column&"-"&$r.value&".doc")
.close
EndWith
EndIf
Next
$xls.close(false)
$word.quit
|