* 139 你好! 我的代码,实际上,已经几易其稿了,因为照各位老师比,水平很低,另外对于每个段落中的药品名称也没掌握好,所以,实际上是今天早上凌晨,才醒悟过来,每个段落的文字,即药品,后面有顿号做标记,前面开始没有;我后来发现“山刺梨”和“刺梨”有重复,所以,决定每个段落前要加一个小撇儿',这样,每个段落的药品才会是唯一的了!——到底哪位老师的代码是最正确的(100%),还请你仔细测试一下。
*
* 我的代码因为就是普通的 VBA 查找,水平所限,很费时,当然也有一部分原因是,我的代码前部分是初始化准备,就是当一个药名后面没有“顿号、”时,前部分初始化会自动加一个顿号;其它比如,药名中有空格、有假回车、有域等都要删除变得正常后,再查找重复药名,很费时间,大约一分钟多,请你耐心等待,继而测试一下(EXCEL对照表中,1代表相等,0代码不相等)。师傅水平低,敬请见谅!
*
* 我的代码:
- Sub aaab查找重复药品名称()
- Dim j As Paragraph
- With ActiveDocument
- .Content.Find.Execute "[^13^11]", , , 1, , , , , , "^p", 2
- .Fields.Unlink
- .ConvertNumbersToText
- .Select
- With Selection
- .Font.Underline = wdUnderlineNone
- CommandBars.FindControl(ID:=122).Execute
- CommandBars.FindControl(ID:=123).Execute
- With .Find
- .ClearFormatting
- .Execute "^w", , , 0, , , , , , "", 2
- .Execute " ", , , 0, , , , , , "", 2
- End With
- End With
- For Each j In .Paragraphs
- If Asc(j.Range) = 13 Then j.Range.Delete
- Next
- .Content.Find.Execute "([!、])(^13)", , , 1, , , , , , "\1、\2", 2
- With .Paragraphs.Last.Range
- If .Text = vbCr Then .Delete
- End With
- .Content.Find.Execute "^p", , , , , , , , , "^p`", 2
- .Paragraphs.Last.Range.Delete
- .Content.InsertBefore Text:="`"
- End With
- 'End Sub
- 'Sub aaab查找重复药品名称222()
- Dim r As Range, a As Range, s As Range, i$, n&
- With Selection
- .WholeStory
- .InsertBefore Text:=vbCr
- Set r = .Range
- Set a = .Range
- Set s = .Paragraphs(1).Range
- End With
- Do
- Set s = s.Next(4, 1)
- If s.Underline = wdUnderlineSingle Then GoTo sk
- With r.Find
- .ClearFormatting
- i = s.Text
- i = Left(i, Len(i) - 1)
- .Text = i
- .Forward = True
- .MatchWildcards = True
- Do While .Execute
- With .Parent
- .MoveEnd
- .Underline = wdUnderlineSingle
- n = n + 1
- If n >= 2 Then .Font.Color = wdColorRed
- .Start = .End
- End With
- Loop
- If n >= 2 Then s.Characters.Last.InsertBefore Text:="(重复" & n & "个)"
- n = 0
- r.SetRange Start:=s.End, End:=a.End
- End With
- sk:
- Loop Until s.End = a.End
- With ActiveDocument.Content
- .Paragraphs(1).Range.Delete
- .Underline = wdUnderlineNone
- .Find.Execute "`", , , , , , , , , "", 2
- End With
- End Sub
复制代码 |