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.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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.
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.
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