PC Review


Reply
Thread Tools Rate Thread

Call Paste function with Undo

 
 
Steven
Guest
Posts: n/a
 
      15th May 2010
Is there any way to call the Paste function using a macro code and with the
undo capability still intact. Everything I have tried the undo is not
available after the Paste.

Thank you,

Steven
 
Reply With Quote
 
 
 
 
FSt1
Guest
Posts: n/a
 
      15th May 2010
hi
a macro skips all of the built in niceities that excel has. undo is one of
them.
see this site.
http://spreadsheetpage.com/index.php...ba_subroutine/

Regards
FSt1

"Steven" wrote:

> Is there any way to call the Paste function using a macro code and with the
> undo capability still intact. Everything I have tried the undo is not
> available after the Paste.
>
> Thank you,
>
> Steven

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      15th May 2010
Here is a sample portion of a macro that shows using the Application.OnUndo
method in operation. Simply copy/paste all the code below into a Module
(Insert/Module from the VB editor menu bar) and then run the YourMacro macro
from a worksheet. Note that setting up the macro I named UndoPaste needs to
be tailored specifically to be able to undo whatever YourMacro actually
did... there is no general Undo that can be implement... you must write the
code to undo whatever your macro does yourself... Excel/VBA will not track
it for you. As written, this code will only Undo the copy/paste operation
with the same workbook. You would have to extend the global variables (those
declared outside of a procedure) and track them yourself in order to be able
to handle multiple workbooks. Here is the code...

'******************** START OF CODE ********************
Dim DestinationCells As String
Dim DestinationData As Variant
Dim DestinationSheet As String

Sub YourMacro()
Dim SourceRange As Range, DestinationRange As Range
'
' <<Beginning Code>>
'
On Error GoTo Whoops
Set SourceRange = Application.InputBox(Prompt:="Select range to copy.", _
Title:="Select Copy Range", Type:=8)
Set DestinationRange = Application.InputBox(Prompt:="Put it where?", _
Title:="Paste Selected Range", Type:=8)
DestinationSheet = ActiveSheet.Name
DestinationCells = DestinationRange.Address
DestinationData = DestinationRange.Resize(SourceRange.Rows.Count, _
SourceRange.Columns.Count)
SourceRange.Copy DestinationRange
Application.OnUndo "Undo Paste Operation", "UndoPaste"
'
' <<Ending Code>>
'
Whoops:
End Sub

Sub UndoPaste()
Range(DestinationCells).Resize(UBound(DestinationData, 1) - _
LBound(DestinationData, 1) + 1, UBound(DestinationData, 2) - _
LBound(DestinationData, 2) + 1) = DestinationData
End Sub
'******************** END OF CODE ********************

--
Rick (MVP - Excel)



"FSt1" <(E-Mail Removed)> wrote in message
news:8CE7556F-7851-4C33-86DF-(E-Mail Removed)...
> hi
> a macro skips all of the built in niceities that excel has. undo is one of
> them.
> see this site.
> http://spreadsheetpage.com/index.php...ba_subroutine/
>
> Regards
> FSt1
>
> "Steven" wrote:
>
>> Is there any way to call the Paste function using a macro code and with
>> the
>> undo capability still intact. Everything I have tried the undo is not
>> available after the Paste.
>>
>> Thank you,
>>
>> Steven


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Undo is being cancelled by a call to bookmark? =?Utf-8?B?Uko=?= Microsoft Access ADP SQL Server 1 26th Oct 2007 05:07 PM
Why is my undo function in Excel only can undo the last 1 or 2 ch. =?Utf-8?B?MTExMTExMTExMTExMTExMTExMTExMTExMTExMTEx Microsoft Excel Worksheet Functions 1 24th Nov 2004 11:13 AM
Cut Copy Paste Undo Keith Microsoft VB .NET 2 24th Jun 2004 08:00 PM
Undo with custom Paste function R Avery Microsoft Excel Programming 1 26th Apr 2004 05:41 PM
User-Defined Function pre-empting Built-in Function? How to undo???? MarWun Microsoft Excel Programming 1 6th Aug 2003 09:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:06 PM.