|
本帖最后由 wx486 于 2014-1-19 15:07 编辑
mbjing 发表于 2014-1-15 18:11
我在excel有一个常用错字清单,大概有上千个字
打开一份几万字文档后,一个个查看错字太麻烦 ... - Sub replaceAll()
- Dim ex As Object, r%, i%, arr, sht, wb
- On Error GoTo errHandle
- Set ex = CreateObject("excel.application")
- Set wb = ex.workbooks.Open(ActiveDocument.Path & "\数据清单.xlsx")
- Set sht = wb.sheets(1)
- Selection.HomeKey wdStory
- With sht
- r = .Cells(.Rows.Count, 1).End(3).Row
- arr = .Range(.Cells(1, 1), .Cells(r, 2))
- End With
- With ActiveDocument.Content.Find
- .Wrap = wdFindContinue
- For i = 2 To r
- .Text = Trim(arr(i, 1))
- .Replacement.Text = Trim(arr(i, 2))
- .Execute Replace:=wdReplaceAll
- Next
- End With
- errHandle:
- wb.Close False
- Set ex = Nothing
- End Sub
复制代码 请测试。 |
评分
-
1
查看全部评分
-
|