|
本帖最后由 duquancai 于 2016-9-22 14:02 编辑
为了提高速度,我还是决定采用正则(当然前提条件是Word文档中有表格也适用!),代码如下,请测试!!!- Sub shishi()
- Dim pt$, f$, wd As Object, n&, m&, wdapp As Object
- Dim oRang As Object, mt, i As Object
- Application.ScreenUpdating = False
- Set wdapp = CreateObject("Word.Application")
- wdapp.Visible = False
- pt = ThisWorkbook.Path & ""
- f = Dir(pt & "*.doc*")
- Do While f <> ""
- Set wd = wdapp.Documents.Open(pt & f, Visible:=False)
- With CreateObject("vbscript.regexp")
- .Pattern = "[a-zA-Z0-9]+"
- .Global = True: .IgnoreCase = False
- For Each i In wd.Paragraphs
- If Len(i.Range.Text) <> 1 Then
- For Each mt In .Execute(i.Range.Text)
- m = mt.FirstIndex: n = mt.Length
- Set oRang = wd.Range(i.Range.Start + m, i.Range.Start + m + n)
- oRang.Font.Name = "Times New Roman"
- Next
- End If
- Next
- End With
- wd.Close True
- f = Dir
- Loop
- wdapp.Quit
- MsgBox "操作完毕!"
- Application.ScreenUpdating = True
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|