Link to home
Start Free TrialLog in
Avatar of rha_mtl
rha_mtl

asked on

Edit exel macro to undo

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
Avatar of Rgonzo1971
Rgonzo1971

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
Avatar of rha_mtl

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial