question

45669932 avatar image
0 Votes"
45669932 asked MiguelManhes-2689 published

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

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.

office-vba-devoffice-word-itpro
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

45669932 avatar image
0 Votes"
45669932 answered MiguelManhes-2689 published

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

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Dude thank you so much, you saved my life!

0 Votes 0 ·