+ Reply to Thread
Results 1 to 7 of 7

Deactivate coding not working??

  1. #1
    Registered User
    Join Date
    08-21-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    48

    Deactivate coding not working??

    Hi I have placed the following code in my spreadsheet but it's not working!

    the code after option explicit (now at the bottom) works, (thanks to Andy on here!) but all the disabling the right click and cut/copy/paste etc doesn't.

    What have I done wrong please????

    Private Sub Workbook_Activate()

    Application.CommandBars("Edit").Controls(3).Enabled = False
    Application.CommandBars("Edit").Controls(4).Enabled = False
    Application.CommandBars("Edit").Controls(5).Enabled = False
    Application.CommandBars("Edit").Controls(6).Enabled = False

    Application.CommandBars("Standard").Controls(7).Enabled = False
    Application.CommandBars("Standard").Controls(8).Enabled = False
    Application.CommandBars("Standard").Controls(9).Enabled = False
    Application.CommandBars("Standard").Controls(10).Enabled = False

    Application.OnKey "^c", ""
    Application.OnKey "^v", ""
    Application.OnKey "^x", ""
    Application.OnKey "^{INSERT}", ""
    Application.OnKey "+{INSERT}", ""
    End Sub

    Private Sub Workbook_Deactivate()

    Application.CommandBars("Edit").Controls(3).Enabled = True
    Application.CommandBars("Edit").Controls(4).Enabled = True
    Application.CommandBars("Edit").Controls(5).Enabled = True
    Application.CommandBars("Edit").Controls(6).Enabled = True

    Application.CommandBars("Standard").Controls(7).Enabled = True
    Application.CommandBars("Standard").Controls(8).Enabled = True
    Application.CommandBars("Standard").Controls(9).Enabled = True
    Application.CommandBars("Standard").Controls(10).Enabled = True

    Application.OnKey "^c"
    Application.OnKey "^v"
    Application.OnKey "^x"
    Application.OnKey "^{INSERT}"
    Application.OnKey "+{INSERT}"
    End Sub

    Option Explicit


    Private Sub Worksheet_Change(ByVal Target As Range)

    If Not Intersect(Target, Range("H20,H21,H22,H23,H24,H25,H26")) Is Nothing Then
    If Target.Value < -2 Or Target.Value > 2 Then
    Target.Offset(21, 0).Activate
    End If
    End If
    End Sub

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Deactivate coding not working??

    Where is the first bit of code located?
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Registered User
    Join Date
    08-21-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    48

    Re: Deactivate coding not working??

    Well I just right clicked on Sheet 1, view code, and entered in the box there?

    The bottom code after option explicit was there and worked, so I added it in front of that?


  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Deactivate coding not working??

    That code has to be located in the ThisWorkbook module of the workbook. It won't work anywhere else.

  5. #5
    Registered User
    Join Date
    08-21-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    48

    Re: Deactivate coding not working??

    FANTASTIC working..

    Can you help me with one thing though, having found the code I thought it would disable right click as well but it doesn't?

    Any ideas please?

    Thanks

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Deactivate coding not working??

    If you want to completely disable the right-click menu for the sheet, then add this to the Worksheet code module:
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-21-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    48

    Re: Deactivate coding not working??

    That is superb, thanks ever so much, off to start a new thread with another question now!!!!!

    Thank you very much indeed

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1