首页 > 解决方案 > 从 Word 粘贴到 Excel 时,Word VBA 宏有时会锁定

问题描述

我是一个尝试编写宏以将信息从 .doc 复制到 .xlsx 文件的外行人。该宏大部分时间都有效,但有时当 Word 打开 Excel 时,它实际上无法将信息粘贴到文件中。

我有一个运行过的测试 .doc,有时可以运行 30 次,但它们似乎随机失败,没有错误消息。它会打开我的 .xlsx 模板,但不会实际粘贴到其中。然后我必须使用任务管理器来杀死 Word 应用程序,除非我完全重新启动 PC,否则宏将无法再次工作。我已经在 Excel 中关闭了实时“启用实时预览”,这似乎有所帮助,但并未完全纠正该问题。

''''
Sub Master_Create_Cut_Packet()
'
'
'
' V2 No longer uses Order Number: to locate header tables for deletion.
'
'
'
' Start search for Install and read in the next two tables and the circuit IDs associated.
' Then compare the two ckt IDs and if they match compare the two tables for matching field and mark column S as Reuse in the pending design if they match.
' Then if Column 9 is blank populate it with NEW_Seq*_
'
'


Dim y As Integer



'Start Check to ensure there are 29 or less circuits in the Circuit.doc file"
    StatusBar = "Counting the number of Install paths."
    Selection.HomeKey Unit:=wdStory      'return to top of doc
    Selection.Find.ClearFormatting
    With ActiveDocument.Content.Find
        Do While .Execute(FindText:="Circuit Id: ", Forward:=True, Format:=True, _
           MatchWholeWord:=True) = True
           y = y + 1
        Loop
    End With
    
    If y > 58 Then
    MsgBox "Circuits.doc has more than 29 circuits in it. This script will only run for a maximun of 29 circuits. Please reduce the number of circuits and rerun the script."
    Exit Sub
    Else
    End If
'End Check to ensure there are 29 or less circuits in the Circuit.doc file"



MsgBox "Please ensure that you do not have the excel file 'Template.xlsx' open. If you do please close it before clicking OK or you may have to restart your PC."



' Start separate_CKT_ID_from_Design_Type Macro
    Selection.HomeKey Unit:=wdStory      'return to top od doc
    StatusBar = "Word is adding a space between the Circuit IDs and (Install) or (Pending)."
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "(Install)"
        .Replacement.Text = " (Install)"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "(Pending)"
        .Replacement.Text = " (Pending)"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
' End separate_CKT_ID_from_Design_Type Macro



' Start search for Install and read in the next two tables and the circuit IDs associated.
' Then compare the two ckt IDs and if they match compare the two tables for matching field and mark column S as Reuse in the pending design if they match.
' Then if Column 9 is blank populate it with NEW_Seq*_

    Dim tbl1 As Table
    Dim tbl2 As Table
    Dim r As Integer
    Dim rr As Integer
    Dim c As Integer
    Dim i As Range
    Dim P As Range

    
    Set tbl1 = ActiveDocument.Tables(1)
    Set tbl2 = ActiveDocument.Tables(2)
    
    StatusBar = "Word is comparing the Install and Pending designs and marking the reuse ports in the S column with 'REUSE_Seq*_'"
    Selection.HomeKey Unit:=wdStory      'return to top of doc
    With Selection.Find
        .Text = "(Install)"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
        Do While Selection.Find.Execute = True
            Selection.MoveLeft Unit:=wdWord, Count:=2
            Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
            Set i = ActiveDocument.Range(Selection.Range.Start, Selection.Range.End)
     
            Selection.GoTo What:=wdGoToTable, Which:=wdGoToNext, Count:=2, Name:=""
            Selection.Tables(1).Select
            
            Selection.MoveRight Unit:=wdWord, Count:=4
            Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
            Set P = ActiveDocument.Range(Selection.Range.Start, Selection.Range.End)
            Selection.GoTo What:=wdGoToTable, Which:=wdGoToNext, Count:=2, Name:=""
            Selection.Tables(1).Select
            
                If i = P Then
                    
                    Else: MsgBox "ALERT: Did not find both a Install and Pending design for: " & i
                          MsgBox "Due to each circuit not having a Install and Pending design this Macro will now stop, please reselect circuits and try again."
                          Selection.GoTo What:=wdGoToTable, Which:=wdGoToPrevious, Count:=1, Name:=""
                          Exit Sub
                End If
        Loop

    Set tbl1 = Nothing
    Set tbl2 = Nothing
' End compare the two ckt IDs and if they match compare the two tables for matching field and mark column S as Reuse in the pending design if they match.



' Start Delete all of the header tables
    StatusBar = "Word is deleting header tables that follows each Circuit ID"
    Selection.HomeKey Unit:=wdStory      'return to top od doc
        Selection.Find.ClearFormatting
        With Selection.Find
            .Text = "(Install)"
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
            Do While Selection.Find.Execute = True
                Selection.GoTo What:=wdGoToTable, Which:=wdGoToNext, Count:=1, Name:=""
                Selection.Tables(1).Select
                Selection.Tables(1).Delete
                Selection.Delete Unit:=wdCharacter, Count:=1
            Loop
                Selection.HomeKey Unit:=wdStory      'return to top od doc
        Selection.Find.ClearFormatting
        With Selection.Find
            .Text = "(Pending)"
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
            Do While Selection.Find.Execute = True
                Selection.GoTo What:=wdGoToTable, Which:=wdGoToNext, Count:=1, Name:=""
                Selection.Tables(1).Select
                Selection.Tables(1).Delete
                Selection.Delete Unit:=wdCharacter, Count:=1
            Loop
    ' End Delete all fo the header tables



' Start find all of the Install Designs and populate empty cells in S column with REUSE_Seq*_
    StatusBar = "Word is finding all of the Install designs and populating the empty cells in S column with 'REUSE_Seq*_'"
    Dim tTable As Table
    Dim cCell As Cell
    Dim sTemp1 As String
    Dim sTemp2 As String
    Dim sTemp3 As String
    
    sTemp1 = "REMOVE_Seq*_"
    sTemp2 = "REUSE_Seq*_"
    sTemp3 = "NEW_Seq*_"
    
    Selection.HomeKey Unit:=wdStory      'return to top of doc
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "(Install)"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Do While Selection.Find.Execute = True
    Selection.GoTo What:=wdGoToTable, Which:=wdGoToNext, Count:=1, Name:=""
    Selection.Tables(1).Select
        If Selection.Information(wdWithInTable) Then
            Set tTable = Selection.Tables(1)
            For Each cCell In tTable.Range.Columns(9).Cells
                If (cCell.Range.Text) = "OUT" & Chr(13) & Chr(7) Then
                    cCell.Range = sTemp1
                ElseIf (cCell.Range.Text) = Chr(13) & Chr(7) Then
                    cCell.Range = sTemp2
                End If
            Next
        End If
    Set oCell = Nothing
    Set tTable = Nothing
    Loop
' End   find all of the Install Designs and populate empty cells in S column with REUSE_Seq*_



' Start search for Install and read in the next two tables and the circuit IDs associated.
' Then compare the two ckt IDs and if they match compare the two tables for matching field and mark column S as Reuse in the pending design if they match.
' Then if Column 9 is blank populate it with NEW_Seq*_

    
    Set tbl1 = ActiveDocument.Tables(1)
    Set tbl2 = ActiveDocument.Tables(2)
    
    StatusBar = "Word is comparing the Install and Pending designs and marking the reuse ports in the S column with 'REUSE_Seq*_'"
    Selection.HomeKey Unit:=wdStory      'return to top of doc
    With Selection.Find
        .Text = "(Install)"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
   End With
        Do While Selection.Find.Execute = True
            Selection.MoveLeft Unit:=wdWord, Count:=2
            Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
            Set i = ActiveDocument.Range(Selection.Range.Start, Selection.Range.End)
     
            Selection.GoTo What:=wdGoToTable, Which:=wdGoToNext, Count:=1, Name:=""
            Selection.Tables(1).Select
            Set tbl1 = Selection.Tables(1)
            
            Selection.MoveRight Unit:=wdWord, Count:=4
           Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
            Set P = ActiveDocument.Range(Selection.Range.Start, Selection.Range.End)
            Selection.GoTo What:=wdGoToTable, Which:=wdGoToNext, Count:=1, Name:=""
            Selection.Tables(1).Select
            Set tbl2 = Selection.Tables(1)
            
                If i = P Then
                    
                    Else: MsgBox "ALERT: Did not find both a Install and Pending design for: " & i
                          MsgBox "Due to each circuit not having a Install and Pending design this Macro will now stop, please reselect circuits and try again."
                          Selection.GoTo What:=wdGoToTable, Which:=wdGoToPrevious, Count:=1, Name:=""
                          Exit Sub
                End If

            
            c = 7 'Which Column to search 1
            For r = 2 To tbl1.Rows.Count
            For rr = 2 To tbl2.Rows.Count
                ' start check site, then object, then additional detail all match
                If tbl1.Cell(r, 1).Range.Text = tbl2.Cell(rr, 1).Range.Text Then
                    If tbl1.Cell(r, 4).Range.Text = tbl2.Cell(rr, 4).Range.Text Then
                        If tbl1.Cell(r, c).Range.Text = tbl2.Cell(rr, c).Range.Text Then
                        tbl2.Cell(rr, 9).Range.Text = sTemp2
                        End If
                    End If
                End If
                ' end check
                If tbl2.Cell(rr, 9).Range.Text = Chr(13) & Chr(7) Then
                    tbl2.Cell(rr, 9).Range.Text = sTemp3
                End If
            Next rr
            Next r
        Loop

    Set tbl1 = Nothing
    Set tbl2 = Nothing
' End compare the two ckt IDs and if they match compare the two tables for matching field and mark column S as Reuse in the pending design if they match.




'*******************************************************************************************************************
'
'
' This will copy all the circuit designs from the Master CLR Markup into an excel template to create a cut packet.
'
'
'
Dim oXL   As Excel.Application
Dim oWB   As Excel.Workbook
Dim tbl As Table
Dim LastRow As Long, LastColumn As Integer
Dim tblRange As Range
Dim wksht As Integer
Dim ii As Integer
Dim x, Response, ExitResponse
Dim Check, Counter
Check = True: Counter = 0    ' Initialize variables.

y = 0
wrsht = 2
Check = True: Counter = 0    ' Initialize variables.



'Start If Excel is running, get a handle on it; otherwise start a new instance of Excel
    StatusBar = "Checking to see if Excel application is open, and if not opening it."

    On Error Resume Next
    Set oXL = GetObject(, "Excel.Application")
    If Err Then
        Set oXL = CreateObject("Excel.Application")
    End If
    On Error GoTo 0
        Set oWB = oXL.Workbooks.Open(FileName:="C:\Temp\Template.xlsx")
        oXL.Visible = True
lbl_Exit:
'End If Excel is running, get a handle on it; otherwise start a new instance of Excel




'Start Search for and count occurrences of the text typed.
    StatusBar = "Counting the number of Install paths."
    Selection.HomeKey Unit:=wdStory      'return to top of doc
    Selection.Find.ClearFormatting
    x = "(Install)"
    With ActiveDocument.Content.Find
        Do While .Execute(FindText:=x, Forward:=True, Format:=True, _
           MatchWholeWord:=True) = True
           y = y + 1
        Loop
    End With
'End Search for and count occurrences of the text typed.
    

    
'Start Run an Outer and Inner Loop to step through the word doc and copy out the information
    Selection.HomeKey Unit:=wdStory      'return to top of doc
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "(Install)"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    
    
    
        Do    ' Outer loop.
                   ' Display message in Word's Status Bar.
                    StatusBar = "Word is moving circuits into Excel Cut Packet"

            If Counter = y Then    ' If condition is True.
                Check = False    ' Set value of flag to False.
                Exit Do    ' Exit inner loop.
            End If
            
            Do While Counter < y    ' Inner loop.
                With Selection
                 .Collapse 'Collapse current selection to an insertion point
                 .Expand Unit:=wdSentence  'Expand selection to current sentence.
                End With
            Selection.Cut
            On Error GoTo errorHandler ' Enable error-handling routine.
                oXL.ActiveWorkbook.Worksheets(wrsht).Paste Destination:=ActiveWorkbook.Worksheets(wrsht).Range("A7")
                Selection.GoTo What:=wdGoToTable, Which:=wdGoToNext, Count:=1, Name:=""
                Selection.Tables(1).Select
                    Set tbl = Selection.Tables(1)
                        With tbl
                        LastRow = .Rows.Count
                        LastColumn = .Columns.Count
                        Set tblRange = .Cell(1, 1).Range
                        tblRange.End = .Cell(LastRow, LastColumn).Range.End
                        tblRange.Cut
                    End With
                For ii = 1 To 200
                Next ii
            On Error GoTo errorHandler ' Enable error-handling routine.
                oXL.ActiveWorkbook.Worksheets(wrsht).Paste Destination:=ActiveWorkbook.Worksheets(wrsht).Range("A8")
                Selection.MoveRight Unit:=wdWord, Count:=1
                    With Selection
                        .Collapse 'Collapse current selection to an insertion point
                        .Expand Unit:=wdSentence  'Expand selection to current sentence.
                    End With
                Selection.Cut
             On Error GoTo errorHandler ' Enable error-handling routine.
                oXL.ActiveWorkbook.Worksheets(wrsht).Paste Destination:=ActiveWorkbook.Worksheets(wrsht).Range("K7")
                Selection.GoTo What:=wdGoToTable, Which:=wdGoToNext, Count:=1, Name:=""
                Selection.Tables(1).Select
                    Set tbl = Selection.Tables(1)
                    With tbl
                        LastRow = .Rows.Count
                        LastColumn = .Columns.Count
                        Set tblRange = .Cell(1, 1).Range
                        tblRange.End = .Cell(LastRow, LastColumn).Range.End
                        tblRange.Cut
                    End With
             On Error GoTo errorHandler ' Enable error-handling routine.
                oXL.ActiveWorkbook.Worksheets(wrsht).Paste Destination:=ActiveWorkbook.Worksheets(wrsht).Range("K8")
                On Error Resume Next
                Selection.MoveRight Unit:=wdWord, Count:=1
                wrsht = wrsht + 1
        
            Counter = Counter + 1    ' Increment Counter.
                If Counter = y Then    ' If condition is True.
                Check = False    ' Set value of flag to False.
            Exit Do    ' Exit inner loop.
            End If
            Loop
        Loop Until Check = False    ' Exit outer loop immediately.
'End Run an Outer and Inner Loop to step through the word doc and copy out the information



'Start Close the Circuit.doc export file
    On Error GoTo WordErrorHandler
    ActiveDocument.Close _
     SaveChanges:=wdDoNotSaveChanges
     Application.WindowState = wdWindowStateMinimize
     
WordErrorHandler:
        If Err = 4198 Then MsgBox "Circuit.doc failed to close."
'End Close the Circuit.doc export file



'Start Release all declared objects
    Set oWB = Nothing
    Set oXL = Nothing
'End Release all declared objects



'Start Release all declared objects
    Set oWB = Nothing
    Set oXL = Nothing
'End Release all declared objects



'Start Exit the main program, everything below this is subroutines
    Exit Sub
'End Exit the main program, everything below this is subroutines



'Start Error handler for copying and pasting
errorHandler:
'    Wait 0.5
For ii = 1 To 1000
Next ii
    Resume
    Exit Sub
'End Error handler for copying and pasting



'Start Error handler for opening Excel application and workbook
Err_Handler:
    MsgBox WorkbookToWorkOn & " caused a problem. " & Err.Description, vbCritical, _
           "Error: " & Err.Number
    If ExcelWasNotRunning Then
        oXL.Quit
    End If
'End Error handler for opening Excel application and workbook



End Sub



Sub Master_Copy_To_Excel_V2()
'
'
' This will copy all the circuit designs from the Master CLR Markup into an excel template to create a cut packet.
'
'
'
Dim oXL   As Excel.Application
Dim oWB   As Excel.Workbook
Dim ExcelWasNotRunning   As Boolean
Dim tbl As Table
Dim LastRow As Long, LastColumn As Integer
Dim tblRange As Range
Dim wksht As Integer
Dim y As Integer
Dim Check, Counter
Dim i As Integer



wrsht = 2
Check = True: Counter = 0    ' Initialize variables.


'MsgBox "Please ensure you do not have the excel file Template.xlsx open.


'Start If Excel is running, get a handle on it; otherwise start a new instance of Excel
    StatusBar = "Checking to see if Excel application is open, and if not opening it."

    On Error Resume Next
    Set oXL = GetObject(, "Excel.Application")
    If Err Then
        Set oXL = CreateObject("Excel.Application")
    End If
    On Error GoTo 0
    Set oWB = oXL.Workbooks.Open(FileName:="C:\Temp\Template.xlsx")
    oXL.Visible = True
lbl_Exit:
'End If Excel is running, get a handle on it; otherwise start a new instance of Excel



'Start Search for and count occurrences of the text typed.
    StatusBar = "Counting the number of Install paths."
    Selection.HomeKey Unit:=wdStory      'return to top of doc
    Selection.Find.ClearFormatting
    x = "(Install)"
    With ActiveDocument.Content.Find
        Do While .Execute(FindText:=x, Forward:=True, Format:=True, _
           MatchWholeWord:=True) = True
           y = y + 1
        Loop
    End With
'End Search for and count occurrences of the text typed.
    

    
'Start Run an Outer and Inner Loop to step through the word doc and copy out the information
    Selection.HomeKey Unit:=wdStory      'return to top of doc
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "(Install)"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    
    
    
        Do    ' Outer loop.
                   ' Display message in Word's Status Bar.
                    StatusBar = "Word is moving circuits into Excel Cut Packet"

            If Counter = y Then    ' If condition is True.
                Check = False    ' Set value of flag to False.
                Exit Do    ' Exit inner loop.
            End If
            
            Do While Counter < y    ' Inner loop.
                With Selection
                 .Collapse 'Collapse current selection to an insertion point
                 .Expand Unit:=wdSentence  'Expand selection to current sentence.
                End With
            Selection.Cut
            On Error GoTo errorHandler ' Enable error-handling routine.
                oXL.ActiveWorkbook.Worksheets(wrsht).Paste Destination:=ActiveWorkbook.Worksheets(wrsht).Range("A7")
                Selection.GoTo What:=wdGoToTable, Which:=wdGoToNext, Count:=1, Name:=""
                Selection.Tables(1).Select
                    Set tbl = Selection.Tables(1)
                        With tbl
                        LastRow = .Rows.Count
                        LastColumn = .Columns.Count
                        Set tblRange = .Cell(1, 1).Range
                        tblRange.End = .Cell(LastRow, LastColumn).Range.End
                        tblRange.Copy
                    End With
            On Error GoTo errorHandler ' Enable error-handling routine.
                oXL.ActiveWorkbook.Worksheets(wrsht).Paste Destination:=ActiveWorkbook.Worksheets(wrsht).Range("A8")
                Selection.MoveRight Unit:=wdWord, Count:=1
                    With Selection
                        .Collapse 'Collapse current selection to an insertion point
                        .Expand Unit:=wdSentence  'Expand selection to current sentence.
                    End With
                Selection.Cut
             On Error GoTo errorHandler ' Enable error-handling routine.
                oXL.ActiveWorkbook.Worksheets(wrsht).Paste Destination:=ActiveWorkbook.Worksheets(wrsht).Range("K7")
                Selection.GoTo What:=wdGoToTable, Which:=wdGoToNext, Count:=1, Name:=""
                Selection.Tables(1).Select
                    Set tbl = Selection.Tables(1)
                    With tbl
                        LastRow = .Rows.Count
                        LastColumn = .Columns.Count
                        Set tblRange = .Cell(1, 1).Range
                        tblRange.End = .Cell(LastRow, LastColumn).Range.End
                        tblRange.Copy
                    End With
             On Error GoTo errorHandler ' Enable error-handling routine.
                oXL.ActiveWorkbook.Worksheets(wrsht).Paste Destination:=ActiveWorkbook.Worksheets(wrsht).Range("K8")
                Selection.MoveRight Unit:=wdWord, Count:=1
                wrsht = wrsht + 1
        
            Counter = Counter + 1    ' Increment Counter.
                If Counter = y Then    ' If condition is True.
                Check = False    ' Set value of flag to False.
            Exit Do    ' Exit inner loop.
            End If
            Loop
        Loop Until Check = False    ' Exit outer loop immediately.
'End Run an Outer and Inner Loop to step through the word doc and copy out the information



'Start Close the Circuit.doc export file
    On Error GoTo WordErrorHandler
    ActiveDocument.Close _
     SaveChanges:=wdDoNotSaveChanges
     Application.WindowState = wdWindowStateMinimize
     
WordErrorHandler:
        If Err = 4198 Then MsgBox "Circuit.doc failed to close."
'End Close the Circuit.doc export file



'Start Release all declared objects
    Set oWB = Nothing
    Set oXL = Nothing
'End Release all declared objects



'Start Release all declared objects
    Set oWB = Nothing
    Set oXL = Nothing
'End Release all declared objects



'Start Exit the main program, everything below this is subroutines
    Exit Sub
'End Exit the main program, everything below this is subroutines



'Start Error handler for copying and pasting
errorHandler:
'    Wait 0.5
For i = 1 To 1000
Next i
    Resume
    Exit Sub
'End Error handler for copying and pasting



'Start Error handler for opening Excel application and workbook
Err_Handler:
    MsgBox WorkbookToWorkOn & " caused a problem. " & Err.Description, vbCritical, _
           "Error: " & Err.Number
    If ExcelWasNotRunning Then
        oXL.Quit
    End If
'End Error handler for opening Excel application and workbook



End Sub
''''

谁能给我一些关于检查什么的想法?

标签: excelvbams-word

解决方案


如果您遇到的复制/粘贴问题不是时间问题(无法通过等待和重试来解决),那么此错误处理程序会将您困在错误等待重试的无限循环中:

'Start Error handler for copying and pasting
errorHandler:
'    Wait 0.5
For ii = 1 To 1000
Next ii
    Resume
    Exit Sub

最好记录您重试的次数,然后在达到某个值(例如,5 或 10 次尝试)时退出该尝试


推荐阅读