<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Catching Paste Operations</title>
	<atom:link href="http://www.dailydoseofexcel.com/archives/2007/12/17/catching-paste-operations/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dailydoseofexcel.com/archives/2007/12/17/catching-paste-operations/</link>
	<description>Daily posts of Excel tips…and other stuff</description>
	<lastBuildDate>Wed, 08 Feb 2012 23:58:05 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: calidor</title>
		<link>http://www.dailydoseofexcel.com/archives/2007/12/17/catching-paste-operations/#comment-51481</link>
		<dc:creator>calidor</dc:creator>
		<pubDate>Wed, 29 Sep 2010 11:11:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1783#comment-51481</guid>
		<description>&lt;p&gt;This workbook..&lt;br&gt;
&#039; Activate/deactivate - we only want to capture ctrl+v on this specific workbook&lt;br&gt;
Private Sub Workbook_Activate()&lt;br&gt;
    Application.OnKey &quot;^v&quot;, &quot;RunMyPaste&quot;&lt;br&gt;
End Sub&lt;/p&gt;
&lt;p&gt;Private Sub Workbook_Deactivate()&lt;br&gt;
    Application.OnKey &quot;^v&quot;&lt;br&gt;
End Sub&lt;/p&gt;
&lt;p&gt;Public Sub RunMyPaste()&lt;/p&gt;
&lt;p&gt;    &#039; worksheet is unprotected for VBA, if cell is locked - do not paste (VBA would allow it)&lt;br&gt;
    If ActiveCell.Locked = True Then&lt;br&gt;
        Exit Sub&lt;br&gt;
    End If&lt;/p&gt;
&lt;p&gt;    Dim DataObj As New MSForms.DataObject&lt;br&gt;
    Dim S As String&lt;br&gt;
    DataObj.GetFromClipboard&lt;/p&gt;
&lt;p&gt;    &#039; Set up for error checking&lt;br&gt;
    On Error Resume Next&lt;br&gt;
    S = DataObj.GetText&lt;/p&gt;
&lt;p&gt;    &#039; Clean non-printable characters&lt;br&gt;
    S = Application.WorksheetFunction.Clean(S)&lt;/p&gt;
&lt;p&gt;    &#039; Check if error and check if zero length (blank)&lt;br&gt;
    If (Err.Number  0) Or (Len(S) = 0) Then&lt;br&gt;
        On Error GoTo 0&lt;br&gt;
        Exit Sub&lt;br&gt;
    End If&lt;/p&gt;
&lt;p&gt;    &#039;Paste&lt;br&gt;
    Application.EnableEvents = False&lt;br&gt;
    Application.ScreenUpdating = False&lt;br&gt;
    &#039;backup cell value&lt;br&gt;
    Dim sValue As String&lt;/p&gt;
&lt;p&gt;    sValue = ActiveCell.Formula&lt;br&gt;
    ActiveCell.Formula = S&lt;/p&gt;
&lt;p&gt;    If ActiveCell.Validation.Value = False Then&lt;br&gt;
        &#039;Give error message&lt;br&gt;
        MsgBox ActiveCell.Validation.ErrorMessage, vbCritical, ActiveCell.Validation.ErrorTitle&lt;br&gt;
        ActiveCell.Value = sValue&lt;br&gt;
        Application.EnableEvents = True&lt;br&gt;
        Application.ScreenUpdating = True&lt;br&gt;
        Exit Sub&lt;br&gt;
    End If&lt;br&gt;
    Application.EnableEvents = True&lt;br&gt;
    Application.ScreenUpdating = True&lt;/p&gt;
&lt;p&gt;    &#039; paste value again so worksheet_change is processed (colors etc)&lt;br&gt;
    ActiveCell.Formula = S&lt;br&gt;
End Sub&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>This workbook..<br />
&#8216; Activate/deactivate &#8211; we only want to capture ctrl+v on this specific workbook<br />
Private Sub Workbook_Activate()<br />
    Application.OnKey &#8220;^v&#8221;, &#8220;RunMyPaste&#8221;<br />
End Sub</p>
<p>Private Sub Workbook_Deactivate()<br />
    Application.OnKey &#8220;^v&#8221;<br />
End Sub</p>
<p>Public Sub RunMyPaste()</p>
<p>    &#8216; worksheet is unprotected for VBA, if cell is locked &#8211; do not paste (VBA would allow it)<br />
    If ActiveCell.Locked = True Then<br />
        Exit Sub<br />
    End If</p>
<p>    Dim DataObj As New MSForms.DataObject<br />
    Dim S As String<br />
    DataObj.GetFromClipboard</p>
<p>    &#8216; Set up for error checking<br />
    On Error Resume Next<br />
    S = DataObj.GetText</p>
<p>    &#8216; Clean non-printable characters<br />
    S = Application.WorksheetFunction.Clean(S)</p>
<p>    &#8216; Check if error and check if zero length (blank)<br />
    If (Err.Number  0) Or (Len(S) = 0) Then<br />
        On Error GoTo 0<br />
        Exit Sub<br />
    End If</p>
<p>    &#8216;Paste<br />
    Application.EnableEvents = False<br />
    Application.ScreenUpdating = False<br />
    &#8216;backup cell value<br />
    Dim sValue As String</p>
<p>    sValue = ActiveCell.Formula<br />
    ActiveCell.Formula = S</p>
<p>    If ActiveCell.Validation.Value = False Then<br />
        &#8216;Give error message<br />
        MsgBox ActiveCell.Validation.ErrorMessage, vbCritical, ActiveCell.Validation.ErrorTitle<br />
        ActiveCell.Value = sValue<br />
        Application.EnableEvents = True<br />
        Application.ScreenUpdating = True<br />
        Exit Sub<br />
    End If<br />
    Application.EnableEvents = True<br />
    Application.ScreenUpdating = True</p>
<p>    &#8216; paste value again so worksheet_change is processed (colors etc)<br />
    ActiveCell.Formula = S<br />
End Sub</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Helen Ellwood</title>
		<link>http://www.dailydoseofexcel.com/archives/2007/12/17/catching-paste-operations/#comment-44175</link>
		<dc:creator>Helen Ellwood</dc:creator>
		<pubDate>Thu, 25 Feb 2010 11:46:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1783#comment-44175</guid>
		<description>&lt;p&gt;This code looks perfect for what I need it for, but the link to &lt;a href=&quot;http://www.savefile.com/files/1398313&quot; rel=&quot;nofollow&quot;&gt;http://www.savefile.com/files/1398313&lt;/a&gt; doesn&#039;t work!&lt;/p&gt;
&lt;p&gt;Bjørnar Tofteland, are you still out there? And is there anywhere else I can get a copy of this code?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>This code looks perfect for what I need it for, but the link to <a href="http://www.savefile.com/files/1398313" rel="nofollow">http://www.savefile.com/files/1398313</a> doesn&#8217;t work!</p>
<p>Bjørnar Tofteland, are you still out there? And is there anywhere else I can get a copy of this code?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Clough</title>
		<link>http://www.dailydoseofexcel.com/archives/2007/12/17/catching-paste-operations/#comment-32130</link>
		<dc:creator>Peter Clough</dc:creator>
		<pubDate>Wed, 30 Apr 2008 22:39:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1783#comment-32130</guid>
		<description>&lt;p&gt;Some thoughts (no code) borrowed from an approach I took to this problem.  First, before the workbook is saved, it hides all sheets except a warning sheet which explains that macros must be enabled to view the meaningful sheets.  Second, all sheets are PW protected and all the fields are locked except data entry cells.  Third, Most editing is done in VBA, so there is little data validation.  Finally, whenever there is a change in a data entry cell, the entry is edited, reset to a non-harmful state if in error, and formats, conditional formats, and validation if any is reapplied from a mask on a hidden sheet, customized to that particular cell or range.  This has multiple advantages:  the user can&#039;t screw up formats or edits (we all do it, usually by inadvertence), 1000 cells never go to div0 or NA or NAME? and force you to debug, it allows paste operations into data entry cells, and it&#039;s relatively secure.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Some thoughts (no code) borrowed from an approach I took to this problem.  First, before the workbook is saved, it hides all sheets except a warning sheet which explains that macros must be enabled to view the meaningful sheets.  Second, all sheets are PW protected and all the fields are locked except data entry cells.  Third, Most editing is done in VBA, so there is little data validation.  Finally, whenever there is a change in a data entry cell, the entry is edited, reset to a non-harmful state if in error, and formats, conditional formats, and validation if any is reapplied from a mask on a hidden sheet, customized to that particular cell or range.  This has multiple advantages:  the user can&#8217;t screw up formats or edits (we all do it, usually by inadvertence), 1000 cells never go to div0 or NA or NAME? and force you to debug, it allows paste operations into data entry cells, and it&#8217;s relatively secure.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bjørnar Tofteland</title>
		<link>http://www.dailydoseofexcel.com/archives/2007/12/17/catching-paste-operations/#comment-30883</link>
		<dc:creator>Bjørnar Tofteland</dc:creator>
		<pubDate>Sat, 23 Feb 2008 16:14:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1783#comment-30883</guid>
		<description>&lt;p&gt;I have used the feedback from jkpieterse and Alistair to modify my project. I have now created a class module to take care of the preserving of datavalidation and formatting.&lt;br&gt;
You can still do as much cut, copy, paste and drag/drop as you like.&lt;br&gt;
The one level undo works for multiple input ranges.&lt;br&gt;
I have also added a couple of UDF&#039;s that I use for all references to the input area, so no references gets destroyed when you cut or drag/drop on cells in the input area.&lt;br&gt;
Inserting cells is prevented by worksheet protection.&lt;br&gt;
For those of you who wants to take a look at this I have made a demo, available from the link below.&lt;br&gt;
This demonsrates the use of this class module on 2 separate input ranges. There is also a output range showing the use of the UDF&#039;s that references the input areas. Try cut/paste and you can see that no references is destroyed.&lt;br&gt;
The use of a template row for all validation and formatting, that Alistair suggested, also makes changes easier, I dont have to copy the changes to all rows, just change the template.&lt;br&gt;
If the user that puts in the data don&#039;t activate the macro&#039;s, he can still use the workbook, and can probably destroy some formatting and validation. But the template cells is hidden and all invalid data is highlighted and can be corrected, when you reopen the workbook with macros activated.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.savefile.com/files/1398313&quot; rel=&quot;nofollow&quot;&gt;http://www.savefile.com/files/1398313&lt;/a&gt;&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I have used the feedback from jkpieterse and Alistair to modify my project. I have now created a class module to take care of the preserving of datavalidation and formatting.<br />
You can still do as much cut, copy, paste and drag/drop as you like.<br />
The one level undo works for multiple input ranges.<br />
I have also added a couple of UDF&#8217;s that I use for all references to the input area, so no references gets destroyed when you cut or drag/drop on cells in the input area.<br />
Inserting cells is prevented by worksheet protection.<br />
For those of you who wants to take a look at this I have made a demo, available from the link below.<br />
This demonsrates the use of this class module on 2 separate input ranges. There is also a output range showing the use of the UDF&#8217;s that references the input areas. Try cut/paste and you can see that no references is destroyed.<br />
The use of a template row for all validation and formatting, that Alistair suggested, also makes changes easier, I dont have to copy the changes to all rows, just change the template.<br />
If the user that puts in the data don&#8217;t activate the macro&#8217;s, he can still use the workbook, and can probably destroy some formatting and validation. But the template cells is hidden and all invalid data is highlighted and can be corrected, when you reopen the workbook with macros activated.</p>
<p><a href="http://www.savefile.com/files/1398313" rel="nofollow">http://www.savefile.com/files/1398313</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bjørnar Tofteland</title>
		<link>http://www.dailydoseofexcel.com/archives/2007/12/17/catching-paste-operations/#comment-30004</link>
		<dc:creator>Bjørnar Tofteland</dc:creator>
		<pubDate>Tue, 22 Jan 2008 06:48:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1783#comment-30004</guid>
		<description>&lt;p&gt;Thanks JK. I tested the Application.OnUndo as my last code and it works perfect.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Thanks JK. I tested the Application.OnUndo as my last code and it works perfect.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jkpieterse</title>
		<link>http://www.dailydoseofexcel.com/archives/2007/12/17/catching-paste-operations/#comment-29987</link>
		<dc:creator>jkpieterse</dc:creator>
		<pubDate>Mon, 21 Jan 2008 10:03:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1783#comment-29987</guid>
		<description>&lt;p&gt;Forgot to add that the Application.OnUndo must be the last entry of your code.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Forgot to add that the Application.OnUndo must be the last entry of your code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jkpieterse</title>
		<link>http://www.dailydoseofexcel.com/archives/2007/12/17/catching-paste-operations/#comment-29986</link>
		<dc:creator>jkpieterse</dc:creator>
		<pubDate>Mon, 21 Jan 2008 10:02:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1783#comment-29986</guid>
		<description>&lt;p&gt;AFAIK if you set the APplication.OnUndo, the button will be enabled, but the hsitory will be limited to one entry: the one you just defined in your code. Indeed the history is wiped by your code. &lt;/p&gt;
&lt;p&gt;Check out this page for an example on building the undo:&lt;br&gt;
&lt;a href=&quot;http://www.jkp-ads.com/Articles/UndoWithVBA00.asp&quot; rel=&quot;nofollow&quot;&gt;http://www.jkp-ads.com/Articles/UndoWithVBA00.asp&lt;/a&gt;&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>AFAIK if you set the APplication.OnUndo, the button will be enabled, but the hsitory will be limited to one entry: the one you just defined in your code. Indeed the history is wiped by your code. </p>
<p>Check out this page for an example on building the undo:<br />
<a href="http://www.jkp-ads.com/Articles/UndoWithVBA00.asp" rel="nofollow">http://www.jkp-ads.com/Articles/UndoWithVBA00.asp</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bjørnar Tofteland</title>
		<link>http://www.dailydoseofexcel.com/archives/2007/12/17/catching-paste-operations/#comment-29937</link>
		<dc:creator>Bjørnar Tofteland</dc:creator>
		<pubDate>Thu, 17 Jan 2008 19:33:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1783#comment-29937</guid>
		<description>&lt;p&gt;Thanks for all your feedback.&lt;/p&gt;
&lt;p&gt;I have not had any time too figure out the undo button yet. At first I also tought that the Application.OnUndo would be a easy solution, but I think Alistair is right about that the button will be disabled, when I actually need it.&lt;br&gt;
The tip about only copying one row is a good tip, and I think I will try to do this. That way I will also be sure that all rows have the same validation and formatting, in case I manage to destroy some of this myself when I make changes to the sheet (with restore function disabled). I then only have to edit and test the first row.&lt;br&gt;
As Alistair mentioned, I have also noticed that the fill handle (the little black + in bottom right corner) in a cell with drop down list is sometimes difficult to reach because of the drop down arrow beeing on top of it.&lt;/p&gt;
&lt;p&gt;I&#039;m also going to use this solution in another Workbook where cells in other sheets will have references to the input range. I see that this could bring up some problems, as jkpieterse pointed out, if the user insert cells or use cut operations, so I might have to do something about this. For many of these references I already use a combination of INDEX and MATCH referencing only to index cells in row 1 and column A, Which is hidden, protected and outside the input range. I think maybe if I use this solution on all references to the input range, the refferences will still be valid even if the user uses cut operations inside the input range.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Thanks for all your feedback.</p>
<p>I have not had any time too figure out the undo button yet. At first I also tought that the Application.OnUndo would be a easy solution, but I think Alistair is right about that the button will be disabled, when I actually need it.<br />
The tip about only copying one row is a good tip, and I think I will try to do this. That way I will also be sure that all rows have the same validation and formatting, in case I manage to destroy some of this myself when I make changes to the sheet (with restore function disabled). I then only have to edit and test the first row.<br />
As Alistair mentioned, I have also noticed that the fill handle (the little black + in bottom right corner) in a cell with drop down list is sometimes difficult to reach because of the drop down arrow beeing on top of it.</p>
<p>I&#8217;m also going to use this solution in another Workbook where cells in other sheets will have references to the input range. I see that this could bring up some problems, as jkpieterse pointed out, if the user insert cells or use cut operations, so I might have to do something about this. For many of these references I already use a combination of INDEX and MATCH referencing only to index cells in row 1 and column A, Which is hidden, protected and outside the input range. I think maybe if I use this solution on all references to the input range, the refferences will still be valid even if the user uses cut operations inside the input range.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alastair</title>
		<link>http://www.dailydoseofexcel.com/archives/2007/12/17/catching-paste-operations/#comment-29908</link>
		<dc:creator>Alastair</dc:creator>
		<pubDate>Wed, 16 Jan 2008 13:34:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1783#comment-29908</guid>
		<description>&lt;p&gt;but the vba restore code clears the undo buffer so the undo buttons are disabled? or have i missed something....&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>but the vba restore code clears the undo buffer so the undo buttons are disabled? or have i missed something&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jkpieterse</title>
		<link>http://www.dailydoseofexcel.com/archives/2007/12/17/catching-paste-operations/#comment-29907</link>
		<dc:creator>jkpieterse</dc:creator>
		<pubDate>Wed, 16 Jan 2008 13:30:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1783#comment-29907</guid>
		<description>&lt;p&gt;Well, you can schedule your undo macro to be run when the user clicks any of the default undo buttons:&lt;/p&gt;
&lt;p&gt;Application.OnUndo &quot;Description of Undo&quot; , &quot;YourUndoSub&quot;&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Well, you can schedule your undo macro to be run when the user clicks any of the default undo buttons:</p>
<p>Application.OnUndo &#8220;Description of Undo&#8221; , &#8220;YourUndoSub&#8221;</p>
]]></content:encoded>
	</item>
</channel>
</rss>

