+ Reply to Thread
Results 1 to 22 of 22

Disable insert row for workbook ONLY

  1. #1
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Disable insert row for workbook ONLY

    I have the following code that disables the insert row option. The problem is that it works for ALL workbooks you have open, not just the one the code is in for. How do i change that so that it only works on the workbook the code is written into?

    Please Login or Register  to view this content.

  2. #2
    Registered User
    Join Date
    11-04-2014
    Location
    India
    MS-Off Ver
    2007
    Posts
    85

    Re: Disable insert row for workbook ONLY

    check if this helps

  3. #3
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Disable insert row for workbook ONLY

    thats where i got the code from in the first place?!

  4. #4
    Registered User
    Join Date
    11-04-2014
    Location
    India
    MS-Off Ver
    2007
    Posts
    85

    Re: Disable insert row for workbook ONLY

    why dont you go for sheet protection then with AllowInsertingColumns:=False, AllowInsertingRows:=False
    You can have this in Private Sub Worksheet_Activate() so that whenever sheet comes to focus, inserting ability goes off

  5. #5
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Disable insert row for workbook ONLY

    i cant go the sheet protection route because I do want the ability to insert colomns and rows but only via a userform i created. I dont want the users to be able to do it the right click way

  6. #6
    Registered User
    Join Date
    11-04-2014
    Location
    India
    MS-Off Ver
    2007
    Posts
    85

    Re: Disable insert row for workbook ONLY

    Well I am not sure. however you may check if this works. having your enable/disable statements inside the For loop. This may work only for the worksheets in the active workbook.
    I have not tried this btw
    Please Login or Register  to view this content.

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

    Re: Disable insert row for workbook ONLY

    If you are using 2010 you can disable the command using XML in the CustomUI part of the workbook. It will then only apply to that workbook.
    Everyone who confuses correlation and causation ends up dead.

  8. #8
    Registered User
    Join Date
    11-04-2014
    Location
    India
    MS-Off Ver
    2007
    Posts
    85

    Re: Disable insert row for workbook ONLY

    Quote Originally Posted by romperstomper View Post
    If you are using 2010 you can disable the command using XML in the CustomUI part of the workbook. It will then only apply to that workbook.
    I would go with this option to avoid complications...
    There are ways to do it in 2007 too with the an UI editor I guess

  9. #9
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Disable insert row for workbook ONLY

    romperstomper - i am using 2010 - care to elaborate on how i do that?

  10. #10
    Registered User
    Join Date
    11-04-2014
    Location
    India
    MS-Off Ver
    2007
    Posts
    85

    Re: Disable insert row for workbook ONLY

    Here is a wonderful resource for knowledge purpose
    You may also have a look at the msdn articles. Its fun to play with the CustomUI

  11. #11
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Disable insert row for workbook ONLY

    still dont see how disabling things on the ribbon will solve my problem??

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

    Re: Disable insert row for workbook ONLY

    You'll need the CustomUI editor - see Ron's site here: http://www.rondebruin.nl/win/section2.htm
    There are lots of examples there - see the section on Context Menus (not Contextual tabs).

  13. #13
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Disable insert row for workbook ONLY

    thanks romperstomper - unfortunately the spreadsheet is used at work, and maintained at work and IT has disabled the ability to install anything not authorised by company policy - so it needs to be VBA code.

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

    Re: Disable insert row for workbook ONLY

    In that case you need to use the same code from the Workbook_Deactivate and Workbook_Activate events to enable/disable the controls as required.

  15. #15
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Disable insert row for workbook ONLY

    but wouldnt that only work if the workbook was closed? Users have my workbook open alongside another and the OTHER workbook is affected by the code in my workbook.

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

    Re: Disable insert row for workbook ONLY

    No - the Deactivate event will trigger when you switch to the other workbook.

  17. #17
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Disable insert row for workbook ONLY

    Would that look like this?

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

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

    Re: Disable insert row for workbook ONLY

    Other way round since True actually enables the control:

    Please Login or Register  to view this content.
    and the events don't have parameters.

  19. #19
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Disable insert row for workbook ONLY

    romperstomper....

    thanks, unfortunately other workbooks are still effected.

    EDIT : Figured out why....the code I have been using is totally rubbish it doesnt disable anything. I had another piece of code in there that kind of works which I have now put into workbook activate/deactivate which works (for delete rows only, i cant grey our insert rows annoyingly)

    Please Login or Register  to view this content.
    Last edited by nickmax1; 11-20-2014 at 11:25 AM.

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

    Re: Disable insert row for workbook ONLY

    You have the wrong ID for Insert Row on the Row menu - you need:
    Please Login or Register  to view this content.

  21. #21
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Disable insert row for workbook ONLY

    awesome thats right!

    my delete colomn code must be wrong too as it doesnt disable it



    Please Login or Register  to view this content.

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

    Re: Disable insert row for workbook ONLY

    It's actually the same Id as the rows one - i.e. 3183

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. error on disable/insert row disable code
    By nickmax1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-09-2014, 05:15 AM
  2. Disable insert row and delete row
    By nickmax1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-10-2013, 06:24 AM
  3. Insert row disable
    By tim5 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-31-2011, 12:43 PM
  4. Excel 2007 : Disable 'enter' key insert
    By greywolfst1 in forum Excel General
    Replies: 2
    Last Post: 12-22-2009, 12:32 PM
  5. [SOLVED] how to disable insert column
    By ndalal in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-11-2006, 01:55 PM

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