A very odd clipboard behaviour !

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
9,619
Office Version
  1. 2016
Platform
  1. Windows
Try this code :
VBA Code:
Option Explicit

#If Win64 Then
    Declare PtrSafe Function OpenClipboard Lib "user32" (ByVal hwnd As LongLong) As Long
    Declare PtrSafe Function CloseClipboard Lib "user32" () As Long
#Else
    Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
    Declare Function CloseClipboard Lib "user32" () As Long
#End If


Sub Test()
    Range("a1").Copy
    OpenClipboard 0
    Application.CutCopyMode = False
    CloseClipboard
End Sub

The above code simply copies Range("A1") to the clipboard and removes the copy marching ants.

Now, after having ran the above code, select another cell and try pasting the contents of the clipboard into it (Ctrl+V).... As I expected, the paste operation works fine and the active cell has now the same content and formats of range("A1") despite having turned CutCopyMode off.

Here is where it gets weird :
Try now changing the contents and\or formats of Range("A1") then perform a new Paste operation into another cell without prior copying . To my surprise, I found that the content of the clipboard has now also changed and contains the new contents and formats of Range("A1") without even doing a re-copy of Range("A") !! ... change the contents and\or formats of Range("A1") again, and the clipboard just changes automatically! This behaviour continues until a new copy operation takes place.

I use Office 2016. I don't know if this odd behaviour happens in other office versions.

I discovered this while trying to answer this post
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
its the same behaviour on Excel365
 
Upvote 0
Yongle; ISY

Thank you both for testing and confirming my finding ... I am already thinking if and when this odd side-effect behaviour can be useful & come in handy

Regards.
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,332
Members
449,077
Latest member
jmsotelo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top