簡體   English   中英

使用宏自動化MS Word

[英]Automation of ms word using macro

嗨,大家好,有人可以幫我,因為這真的給我帶來了很大的困難,我是新創建宏的人,所以請盡可能簡單地幫助我:)

我創建了一個宏,用於在兩個不同的文檔中復制和粘貼特定的文本。 我幾乎完成了。 運行宏的過程運行正常,但問題是當我單擊完成的消息時,我的ms字沒有響應,我真的不知道為什么,但有時它會起作用。

有人可以幫助我解決問題,還是可以有人重構我的代碼以獲得更好的輸出,謝謝。

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