本帖最后由 zzpsx 于 2020-5-14 19:42 编辑
如何检验每个红色下划线的单词都只出现了一次.rar
(18.19 KB, 下载次数: 1)
如何检验每个红色下划线的单词都只出现了一次,如果均为唯一值,则不弹窗。如果这些单词出现了两次或多次,就将它们标绿,这样的代码怎么写? Valentine's Day is not a public holiday. Government offices, stores,schools and other organizations are open as usual. Public transit systems runon their regular schedule. Restaurants may be busier than usual as many people go out for an evening withtheir spouse or partner. Valentine's Day is also a very popular date forweddings. There are a number of Saints called Valentine who are honored onFebruary 14. The day became associated with romantic love in the Middle Ages inEngland. This may have followed on fromthe Pagan fertility festivals that were heldall over Europe as the winter came to an end. Traditionally, lovers exchanged hand written notes. Commercial cards became available in the mid nineteenth century. The most common Valentine's Day symbols are the heart, particularlyin reds and pinks, and pictures or models of Cupid. Cupid is usually portrayedas a small winged figure with a bow and arrow. In mythology, he uses his arrowto strike the hearts of people. Peoplewho have fallen in love are sometimessaid to be 'struck by Cupid's arrow. Other symbols of Valentine's Day are couples in loving embraces and the gifts offlowers, chocolate, red roses andlingerie that couples often give each other.
目前找到了这代码https://blog.csdn.net/weixin_44559388/article/details/87396419
Sub 统计各单词出现的次数() Dim a As String, Dic As Object Dim myReg As Object, Matches As Object, Match As Object Dim k, i As Long, j As Long, temp As String, c As String a = ActiveDocument.Content.TextSet Dic = CreateObject("Scripting.Dictionary")Dic.CompareMode = vbTextCompareSet myReg = CreateObject("VBScript.RegExp")With myReg .Pattern = "[A-Za-z]+" '匹配模式:由纯字母组成的字符串 .Global = True Set Matches = .Execute(a) For Each Match In Matches '统计频次 With Match If Dic.Exists(.Value) Then Dic(.Value) = Dic(.Value) + 1 Else Dic.Add .Value, 1 End With Next k = Dic.Keys '获取各“单词” For i = 0 To UBound(k) - 1 '排序 For j = i + 1 To UBound(k) If k(i) > k(j) Then temp = k(i) k(i) = k(j) k(j) = temp End If Next Next For i = 0 To UBound(k) '合并以用于输出 c = c & k(i) & vbTab & Dic(k(i)) & Chr(13) Next Documents.Add.Content.Text = "共有如下" & Dic.Count & "个英文单词(含频次):" & Chr(13) & c End WithEnd Sub
|