Vba 用宏实现ms-word的自动化

Vba 用宏实现ms-word的自动化,vba,Vba,嗨,伙计们,有人能帮我吗?因为这真的给了我一段艰难的时光,我是一个新创建宏的人,所以请尽可能简单地帮助我: 我创建了一个宏,用于复制和粘贴两个不同文档中的特定文本。这件事我差不多做完了。运行宏的过程运行正常,但问题是当我单击“完成”消息时,我的ms word没有响应,我真的不知道为什么,但有时它工作正常 有人能帮我解决这个问题吗?或者有人能重建我的代码以获得更好的输出吗?谢谢 enter code here Dim iCount As Long iCount = 0 Dim MyAr() As

嗨,伙计们,有人能帮我吗?因为这真的给了我一段艰难的时光,我是一个新创建宏的人,所以请尽可能简单地帮助我:

我创建了一个宏,用于复制和粘贴两个不同文档中的特定文本。这件事我差不多做完了。运行宏的过程运行正常,但问题是当我单击“完成”消息时,我的ms word没有响应,我真的不知道为什么,但有时它工作正常

有人能帮我解决这个问题吗?或者有人能重建我的代码以获得更好的输出吗?谢谢

enter code here
Dim iCount As Long
iCount = 0

Dim MyAr() As String
Dim i As Integer
i = 0

Do
ContinueLoop:
iCount = iCount + 1
Selection.EndKey unit:=wdStory
Selection.Find.ClearFormatting
With Selection.Find
    .Text = "checksum*>"""
    .Replacement.Text = ""
    .Forward = False
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
End With
If Selection.Find.Execute = False Then
MSG = MsgBox("Done Checking")
Selection.Find.Text = ","
Selection.Find.Execute Replace:=wdReplaceAll
Exit Do
Else
End If

Selection.MoveRight unit:=wdCharacter, Count:=2
Selection.Find.ClearFormatting
With Selection.Find
    .Text = "*?.pdf"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
End With

Selection.Find.Execute
 ReDim Preserve MyAr(i)
    MyAr(i) = Selection

Windows(1).Activate

Selection.HomeKey unit:=wdStory
Selection.Find.ClearFormatting
With Selection.Find
    .Text = MyAr(0)
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
End With

If Selection.Find.Execute = True Then
Selection.Find.ClearFormatting
With Selection.Find
    .Text = "keying*>"""
    .Replacement.Text = ""
    .Wrap = wdFindContinue
    .MatchWildcards = True
End With
Selection.Find.Execute
Selection.MoveRight unit:=wdCharacter, Count:=2
Windows(2).Activate
Selection.MoveUp unit:=wdParagraph, Count:=1
Selection.MoveDown unit:=wdLine, Count:=2, Extend:=wdExtend
Selection.Cut
Windows(1).Activate
Selection.TypeParagraph
Selection.PasteAndFormat (wdPasteDefault)
Windows(2).Activate
Else
Windows(2).Activate
Selection.MoveUp unit:=wdParagraph, Count:=1
Selection.MoveDown unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.Cut
Selection.HomeKey unit:=wdStory
Selection.PasteAndFormat (wdPasteDefault)
Selection.MoveUp unit:=wdParagraph, Count:=1
Selection.Find.Text = "ck"
Selection.Find.Execute
Selection.MoveRight unit:=wdCharacter, Count:=1
Selection.TypeText Text:=","

GoTo ContinueLoop
   End If
Loop While Selection.Find.Execute = False

我认为您有一个无休止的循环-在selection.find.execute=true时将最后一行更改为loop,以便在find=false时停止搜索