我需要VBA查询"查找"和"替换"

时间:2014-10-29 18:03:27

标签: vba replace

我需要有关"Find""Replace"

的VBA查询
  • 在word文档中我需要根据Defined excel sheet Dictionary(Excel工作表名称:Pardu)进行更改单词 Excel工作表位置:"D:\Documents and Settings\Administrator\Desktop\Pardu.xlsx"

示例:在word文档中,预定义的单词'Goodboy'(A2单元格单词)应更改为'Good Boy'(B2单元格单词)

就像那样......基于A和B列,我需要将所有'Column A words'替换为'Column B words'

A1= NATIVE  REPLACE B1
A2= Goodboy Good Boy    B2
A3= Hw ar you   How are you?    B3
A4= Paardu  Pardu   B4
A5= :',.lk  kqwljn  B5

请将查询发送至:mynameispardu@gmail.com

谢谢你, Pardu。

1 个答案:

答案 0 :(得分:0)

需要精确的vba查询,如下所示..

Sub Pardu()
'
' Pardu Macro
'
Sub Main()
Dim xl As Object 'Excel.Application
Dim wb As Object 'Excel.Workbook
Dim ws As Object 'Excel.Worksheet
Dim rng As Object 'Excel.Range
Dim cl As Object  'Excel.Range
Set xl = CreateObject("Excel.Application")
Set wb = xl.Workbooks.Open("D:\Documents and Settings\Administrator\Desktop\Pardu.xlsx") '## Modify as needed
Set ws = wb.Sheets(1) '##Modify as needed
Set rng = ws.Range("A2", ws.Range("B2").End(xlDown))
For Each cl In rng
    Call Macro5(cl.Value, cl.Offset(0, 1).Value)
Next
End Sub