PDA

View Full Version : When to Use "Application.CutCopyMode" Statement



Cyberdude
05-11-2008, 10:46 AM
Will someone give me a short tutorial about when to use the statement "Application.CutCopyMode = "? It would seem that maybe it should be a standard statement at the end of most macros that do any copying, but I'm just guessing.

Simon Lloyd
05-11-2008, 11:11 AM
I don't know about tutorial as i'm no guru but here goes:
this first copy 'n' paste is how you would expect to perform the action manually, i.e all the clicks or keystrokes
Sub Copy1()
Range("A1").Select
Selection.Copy
Range("B1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
End Sub
thsi next one is exactly the same as the first but performed by VBA and has a specific destination whereas the first did not until you clicked itSub Copy2()
Range("A1").Copy Destination:=Range("B2")
End Subthe next is for copying a component of the cell, i.e the format or value ...etc, here again there is no destination cell until you click it
Sub Copy3()
Range("A1").Select
Selection.Copy
Range("E3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
End Subhere's the same in a shortened version but although we have designated the cell straight away the following actions are only part of a copy and therefore copyMode is still in place for you to paste another componentSub Copy4()
Range("A1").Copy
Range("E6").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Subin short using "Application.CutCopyMode=" clears excels memory so nothing further can be pasted from that selection.

I may not be dead accurate with the explanation and someone may put me right but its as near as damn it!

Norie
05-11-2008, 11:26 AM
Cyberdude

There might not be any need to use it anywhere.

It really depends what you are doing.

If you are using Paste or PasteSpecial then you probably should be using it.

Cyberdude
05-11-2008, 11:27 AM
Thanx for the reply, Simon. Basically, one might say that if you have done a lot of copying in your macro, then you can clear all the memory used by the copy operations by executing CutCopyMode. If copying just small amounts, then there's no real advantage to using CutCopyMode.
Can I assume that CutCopyMode is essentially useless if no copying has been done in the macro? I mean, is it strictly related to copying processes and no others?

Simon Lloyd
05-11-2008, 11:47 AM
Purely copying!

david000
05-11-2008, 11:21 PM
There is one ultra obscure reason to check that you cleared the clipboard, but I don?t have the example anymore.

Anybody that has John Walkenbach?s aka J-Walks Pup2000 (old) AddIn with source code can see this. He used a logo that did not clear the clipboard (how it got there is the bug) if you loaded the right-click menu shortcuts.

I don?t have it on me but I did email J-Walk about this issue and he told me how to fix it (I was so in awe of him at the time).

mdmackillop
05-12-2008, 12:20 AM
I would use it even after small "copies" to avoid unexpected results.

Edit:
I had an issue in some code where the clipboard would not clear. As a workaround I used this to put a null string there.

Cells(Rows.Count,1).Copy