|
楼主 |
发表于 2015-3-11 23:13
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
好象没什么人注意到我的问题,想了一上午,我自己写了段程序草稿出来,基本能达到所需功能,但程序效率太低,一个千页文档要花5分钟以上才能执行完程序,不具有实用价值,请有心人指教下。程序代码如下:
- Public Sub mySearch()
- ScreenUpdating = False
- Dim findString As String
- findString = InputBox("输入要查找的内容", "包括", "")
- '-------------
- '抽取查找内容的单字给数组
- Dim myArray() As String
- Dim cou As Long
- Dim findStringLen As Long
- findStringLen = Len(findString)
- ReDim myArray(1 To findStringLen)
- For cou = 1 To findStringLen Step 1
- myArray(cou) = Mid(findString, cou, 1)
- Next cou
- '------------------------------
- Dim carCout As Long
- carCout = ActiveDocument.Characters.count '文档所含字数
- '-----------------------------
- cou = 0
- Dim carStart As Long
- Dim carEnd As Long
- carStart = 0
- carEnd = 0
- Dim myRange As Range
- Dim myString As String
- Dim logic1 As Boolean
- Dim logic2 As Boolean
- logic1 = True
- logic2 = True
- Do While carEnd < carCout
- carEnd = carStart + 100
- Set myRange = ActiveDocument.Range(Start:=carStart, End:=carEnd)
- myString = myRange.text
- 'Debug.Print myString
- For cou = 1 To findStringLen Step 1
- If InStr(1, myString, myArray(cou), 1) > 0 Then
- logic1 = True
- Else
- logic1 = False
- End If
- logic1 = logic1 And logic2
- logic2 = logic1
- Debug.Print logic1
- Next cou
- If logic1 = True Then myRange.HighlightColorIndex = wdYellow
- carStart = carStart + 1
- logic1 = True
- logic2 = True
- Loop
- ScreenUpdating = True
- End Sub
复制代码 |
|