|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
先抛出问题:为什么Dic(F.Parent) = ""与Dic(Mid(F.Parent.Paragraphs(1).Range.Text, InStr(F.Parent.Paragraphs(1).Range.Text, F.Parent), 2)) = ""会不一样?
工作中想先用find功能搜索到关键词组,再去重。用Dic(Mid(F.Parent.Paragraphs(1).Range.Text, InStr(F.Parent.Paragraphs(1).Range.Text, F.Parent), 2)) = ""可以实现搜索到的关键词组去重;但用Dic(F.Parent) = ""却只能得到最后一组关键词组?先自行找了各种资料,还是不解。
望各位老师指点迷津,谢谢。
完整代码如下:
Sub UniqueParent()
Dim objDoc As Object, WdFileName As Variant, F As Object, Dic As Variant
Range("A2:C100").ClearContents
On Error Resume Next
Set Dic = CreateObject("scripting.dictionary")
WdFileName = Application.GetOpenFilename("Word files,*.doc?", , "Browse for file containing table to be imported")
If WdFileName = False Then Exit Sub
Set objDoc = GetObject(WdFileName)
Set F = objDoc.Content.Find
F.Text = [G2]
F.MatchWildcards = [H2] '使用通配符”
Do While F.Execute
' Dic(F.Parent) = ""
Dic(Mid(F.Parent.Paragraphs(1).Range.Text, InStr(F.Parent.Paragraphs(1).Range.Text, F.Parent), 2)) = ""
Cells(Dic.Count + 1, 1) = Dic.Count
Debug.Print F.Parent
Loop
[b2].Resize(UBound(Dic.keys) + 1, 1) = Application.Transpose(Dic.keys)
objDoc.Close False
End Sub
|
|