Jaafar Tribak
Well-known Member
- Joined
- Dec 5, 2002
- Messages
- 9,807
- Office Version
- 2016
- Platform
- Windows
Try this code :
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
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