ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Deactivate / Reactivate the Paste Function in excel (https://www.excelbanter.com/excel-programming/404319-deactivate-reactivate-paste-function-excel.html)

missk

Deactivate / Reactivate the Paste Function in excel
 
Hi,

I have a macro that deactivates the paste function in excel.
The re-activation of the paste function occurs before the file is
close (beforeclose), see below.
I have applied this to multiple workbooks, but I noticed that when I
have multiple workbook open, if I close one workbook then the paste
function is effective switch back on. Is there a way around this?

Instead of beforeclose could I trigger the re-activation only when
excel is shut down completely?

Thank you

Private Sub Workbook_BeforeClose(Cancel As Boolean)
' Enable the menu:
Application.CommandBars("Edit").Controls(3).Enable d = True
Application.CommandBars("Edit").Controls(4).Enable d = True
Application.CommandBars("Edit").Controls(5).Enable d = True
Application.CommandBars("Edit").Controls(6).Enable d = True
' Enable the commandbar:
Application.CommandBars("Standard").Controls(7).En abled = True
Application.CommandBars("Standard").Controls(8).En abled = True
Application.CommandBars("Standard").Controls(9).En abled = True
Application.CommandBars("Standard").Controls(10).E nabled = True
' Enable the shortcut keys:
Application.OnKey "^c"
Application.OnKey "^v"
Application.OnKey "^x"
Application.CommandBars("Cell").Enabled = True

End Sub

Nigel[_2_]

Deactivate / Reactivate the Paste Function in excel
 
Not really, but you could include a check that count the number of workbooks
open before you run this code. If it is only one then you know it is the
last one?

e.g.

If Workbooks.Count = 1 then
'Run your code
End if


--

Regards,
Nigel




"missk" wrote in message
...
Hi,

I have a macro that deactivates the paste function in excel.
The re-activation of the paste function occurs before the file is
close (beforeclose), see below.
I have applied this to multiple workbooks, but I noticed that when I
have multiple workbook open, if I close one workbook then the paste
function is effective switch back on. Is there a way around this?

Instead of beforeclose could I trigger the re-activation only when
excel is shut down completely?

Thank you

Private Sub Workbook_BeforeClose(Cancel As Boolean)
' Enable the menu:
Application.CommandBars("Edit").Controls(3).Enable d = True
Application.CommandBars("Edit").Controls(4).Enable d = True
Application.CommandBars("Edit").Controls(5).Enable d = True
Application.CommandBars("Edit").Controls(6).Enable d = True
' Enable the commandbar:
Application.CommandBars("Standard").Controls(7).En abled = True
Application.CommandBars("Standard").Controls(8).En abled = True
Application.CommandBars("Standard").Controls(9).En abled = True
Application.CommandBars("Standard").Controls(10).E nabled = True
' Enable the shortcut keys:
Application.OnKey "^c"
Application.OnKey "^v"
Application.OnKey "^x"
Application.CommandBars("Cell").Enabled = True

End Sub




All times are GMT +1. The time now is 08:52 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com