简体   繁体   English

使用宏自动化MS Word

[英]Automation of ms word using macro

Hi Guys can someone help me because its really giving me a hard time i am new in creating macro so plz help me as simple as you can :) 嗨,大家好,有人可以帮我,因为这真的给我带来了很大的困难,我是新创建宏的人,所以请尽可能简单地帮助我:)

I've created a macro for copying and pasting specific text in two different documents. 我创建了一个宏,用于在两个不同的文档中复制和粘贴特定的文本。 I'm almost done with this. 我几乎完成了。 The process while running the macro is working fine but the problem is when i click the done message my ms word become not responding i really don't know why but sometimes it's working. 运行宏的过程运行正常,但问题是当我单击完成的消息时,我的ms字没有响应,我真的不知道为什么,但有时它会起作用。

Can someone help me figuring out the problem or can someone reconstruct my codes for a better output thanks. 有人可以帮助我解决问题,还是可以有人重构我的代码以获得更好的输出,谢谢。

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

我认为您有一个无限循环-将最后一行更改为“ Loop while selection.find.execute = true”,因此一旦find = false,它将停止搜索。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM