Solved

Edit exel macro to undo

Posted on 2014-03-19
3
93 Views
Last Modified: 2014-08-05
Hello,

Is there a way to undo a macro. Refer to my other Make excel macro available to all users link for the creation and implementation of the macro, typing ctl + L. Right now that function doesn't work.

Thanks
0
Comment
Question by:rha_mtl
  • 2
3 Comments
 
LVL 48

Expert Comment

by:Rgonzo1971
ID: 39939759
To be able to do an Undo

you have to code the undo

Sub MyMacro()
'YourCode
Application.OnUndo "Undo the last macro", "UndoMyMacro"
End Sub

Sub UndoMyMacro()
'YourUndoCode
End Sub

Open in new window

Regards
0
 

Author Comment

by:rha_mtl
ID: 39939815
Hello,

A little confused on where to apply this.

The code I use is

Sub CopyPicture()
Dim WSThis As Worksheet
Dim WS As Worksheet
Dim Img As OLEObject
Dim WSImg As OLEObject

Set WS = ActiveSheet
Set WSThis = ThisWorkbook.Worksheets("Main")

On Error Resume Next
Set WSImg = WS.OLEObjects("Image1")
If Err = 0 Then
    
Else
    Set Img = WSThis.OLEObjects("Image1")
    Img.Copy
    WS.Range("A1").PasteSpecial
End If
On Error GoTo 0

End Sub

Open in new window



Would I select the keys ctl + L to run the undo code. Much like how I do ctl + L to apply run the code
0
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39939842
That would be on line 20

but on your case I don' see how it would be possible to do a reverse command for the paste special

Regards
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now