有四种情况
我希望当我发现这四个案件时,
.text="Proc. Natl. Acad. Sci. )([!U])"
.text="Proc. Natl. Acad. Sci. )([!U])"
.text="Proc. Natl. Acad. Sci. U.S.A."
.text="Proc. Natl. Acad. Sci. U S A"
我用" Proc替换了它们。国家科。科学院。科学。美国" ,
.replacement.text = "Proc. Natl. Acad. Sci. USA"
和我的代码如下。但是当它运行时,msgbox:
我错在哪里,字典功能不能使用通配符?
Sub proc_usa()
Dim pattern_array As Variant, reminder_array As Variant
Call layout_search_replace.jump_to_reference_section
pattern_array = Split("(Proc. Natl. Acad. Sci. )([!U])<<>>(Proc Natl Acad Sci )([!U])<<>>Proc. Natl. Acad. Sci. U.S.A.<<>>Proc. Natl. Acad. Sci. U S A", "<<>>")
Set dict = CreateObject("Scripting.Dictionary")
dict.Add 0, "\1USA "
dict.Add 1, "Proc. Natl. Acad. Sci. \2"
dict.Add 2, "Proc. Natl. Acad. Sci. USA"
dict.Add 3, "Proc. Natl. Acad. Sci. USA"
For i = LBound(pattern_array) To UBound(pattern_array)
With selection.Find
.Text = pattern_array(i)
.MatchWildcards = True
.Wrap = wdFindContinue
.Forward = True
Do
.Execute
If Not .Found Then
Exit Do
End If
If .Found Then
.Replacement.Text = dict(i)
.Execute Replace:=wdReplaceOne
selection.MoveRight unit:=wdCharacter, count:=1
End If
Loop
End With
Next i
Set dict = Nothing
End Sub