none
Word is unable to paste something it just had copied, ends with VBA error 4605 RRS feed

  • Question

  • Hello everybody,

    at a customer's site there are Word macros running since _decades_ just fine. One thing they do is copy the whole current document's Range (into the Windows clipboard), create a new document, and Paste in the new document's Range.

    Since a few weeks, the customer uses Office 365 (32 bit), and code like this fails:

    sourceRange.Copy()
    destinationRange.Paste()

    VBA stops with error 4605 on the Paste() call. We could somewhat help by inserting a DoEvents() between Copy() and Paste(). But this does not help always.

    What did change in Word's handling of the clipboard so that something copied just one statement before cannot be pasted?


    Best Regards, Stefan Falk

    Wednesday, July 17, 2019 5:01 PM

All replies

  • Hi,

    This IT Professionals Word forum is for general questions and feedback related to Word. Your question is mainly related to using VBA in Word. To help you better resolve the issue, I will move the thread to Word for Developers Forum. You may get more helpful replies there.

    Thanks for your kind understanding.

    Best Regards,

    Herb


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Office 2019.

    Thursday, July 18, 2019 2:59 AM
  • Just a guess really, but either
     a. it is "just" a timing problem, in which case you may be able to solve the problem by detecting the error and repeating a DoEvents until the command succeeds, or
     b. it is *sometimes* because more recent versions of Word display more "blocking" messages/warnings than older versions and a Windows is failing to open as a consequence of that.

    I don't know what you could do if it is (b) except try to find out what warning or Word is popping up and trying to switch it off in the settings,

    But if it is (a), you could for example use

    Const maxPasteRetryCount As Long = 20
    Dim pasteRetryCount as Long
    
    pasteRetryCount = 0
    paste:
      DoEvents
      On Error Goto pasteproblem
      destinationRange.Paste()
      On Error Goto 0
    
    ' then further down have:
    
    pasteproblem:
    If Err.Number = 4605 Then
      If  pasteRetryCount >= maxPasteRetryCount then 
        msgbox "some suitable error message"
      Else
        pasteRetryCOunt = pasteRetryCount + 1
        Err.Clear
        Resume paste
      End If
    End If
    


    Alternatively, you might be able to avoid the Error checking approach and test the existence of destinationRange, e.g.

    Const maxRetryCount As Long = 20
    Dim retryCount as Long
    
    retryCount = 0
    Do While ( destinationRange Is Nothing) And ( retryCount < maxRetryCount )
      DoEvents
      retryCount = retryCount + 1
    Loop
    
    If (destinationRange Is Nothing) Then
     ' inform the user
    Else
      destinationRange.Paste
    End If



    Peter Jamieson

    Monday, July 22, 2019 4:16 PM