I am working on a small project that is complete but when i close the workbook and open a new workbook, my paste special/values macro that overrides the paste in the right click menu is still active. How do I disable all macros automatically upon closing workbook or how to disable specific macros auto.
here is the code for the paste special/values used on auto open and also a module.
Sub Auto_Open()
Application.CommandBars("Cell").Reset
With Application.CommandBars("Cell")
.Controls("Paste").OnAction = "PasteValues" ' Changes right click cell paste to use Pastevalues macro
End With
Application.CommandBars("Row").Reset
With Application.CommandBars("Row")
.Controls("Paste").OnAction = "PasteValues" ' Changes right click row paste to use Pastevalues macro
End With
Application.CommandBars("Column").Reset
With Application.CommandBars("Column")
.Controls("Paste").OnAction = "PasteValues" ' Changes right click column paste to use Pastevalues macro
End With
Application.CommandBars("Worksheet Menu Bar").Reset
With Application.CommandBars("Worksheet Menu Bar").Controls
.Item(2).Controls(6).OnAction = "PasteValues" ' changes edit/paste to use Pastevalues macro
.Item(2).Controls(7).Enabled = False ' disable paste special
End With
Application.CommandBars("Standard").Reset
With Application.CommandBars("Standard").Controls.Item(12)
.Enabled = False
End With
If Workbook_Deactivate Then End Sub
End Sub
Sub pastevalues()
On Error Resume Next
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
End Sub
This is what I have in ThisWorkBook to disable/enable cut, delete and cellDragDrop.
Private Sub Workbook_Activate()
Dim ctrl As Office.CommandBarControl
For Each ctrl In Application.CommandBars.FindControls(ID:=21) 'Disable Cut
ctrl.Enabled = False
Next ctrl
For Each ctrl In Application.CommandBars.FindControls(ID:=292) 'Disable Delete
ctrl.Enabled = False
Next
Application.CellDragAndDrop = False
End Sub
Private Sub Workbook_Deactivate()
Dim ctrl As Office.CommandBarControl
For Each ctrl In Application.CommandBars.FindControls(ID:=21) 'Enable Cut
ctrl.Enabled = True
Next ctrl
For Each ctrl In Application.CommandBars.FindControls(ID:=292) 'Enable Delete
ctrl.Enabled = True
Next
Application.CellDragAndDrop = True
End Sub
Thanks for the help.
Bookmarks