MS365 Word VBA Selection.Paste Word Table Run-time error: 4605, but not debug

Glenn Sasscer 11 Reputation points
2021-09-20T12:48:08.11+00:00

MS 365 Word VBA Macro

Copies table at beginning of macro for use later, then changes original table for desired output.

Several sub-routines later, it copies the table from the clipboard.

Prior to MS365, this worked without an issue.

Now, we get Run-time error 4605, This method or property is not available because the Clipboard is empty or not valid.

When we debug the error and press the F8 key, the contents of the Clipboard paste without a problem. If we click the run button on the error, the macro pastes the contents and continues with operation until the copied table is required again, at which time the same error occurs. Same result. F8 and run both proceed to copy the contents and continue operation.

Tried changing to Selection.PasteSpecial. Same result.

Tried clearing the clipboard. Same result.

Tried turning off clipboard history. Same result.

Tried turning off smart copy paste option. Same result.

Tried various options with Selection.PasteSpecial using various DataTypes. None worked or we got the same result.

We can manually paste the contents from the clipboard at that same place in the code (after ending the code).

What's strange is the debug mode will paste the contents, but the run-time will not.

Here is what copies the table:

 DOCNAME1.Tables(1).Select
 DOCNAME1.Tables(1).AutoFitBehavior wdAutoFitFixed
 Selection.HomeKey Unit:=wdStory, Extend:=wdMove
 Selection.WholeStory
 Selection.Copy

Also tried

DOCNAME1.Tables(1).Copy

And, also used the range method... was able to get all three to copy the table to the Clipboard, but none changed the manner in which it is pasted.

Code for pasting is simply:

Selection.PasteSpecial

or the original:

Selection.Paste

Any thoughts? Ideas? Please help.

Word Management
Word Management
Word: A family of Microsoft word processing software products for creating web, email, and print documents.Management: The act or process of organizing, handling, directing or controlling something.
941 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Glenn Sasscer 11 Reputation points
    2021-09-20T22:28:16.597+00:00

    Thank you, JohnKorchok.

    That worked. A one second pause is all it took.

    For reference (for others who might run into this issue), I had the following private sub for another delay elsewhere in the routine:

    Private Sub TIMERUN(SEC)
    PauseTime = SEC ' Set duration.
    Start = TIMER ' Set start time.
    Do While TIMER < Start + PauseTime
    DoEvents ' Yield to other processes.
    Loop
    End Sub

    So, based on your answer, I added the call to the line just before the selection.paste:

    Call TIMERUN(1)
    Selection.Paste

    2 people found this answer helpful.

  2. JS 11 Reputation points
    2022-05-10T19:43:24.32+00:00

    I was experiencing the same issue in some of my VBA procedures after upgrading to M365.

    A simple "DoEvents" line before the paste line has so far resolved the issue for me.

    2 people found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.