+ Reply to Thread
Results 1 to 10 of 10

How to make CommandButton private to designated workbook?

  1. #1
    Registered User
    Join Date
    03-01-2010
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003
    Posts
    57

    How to make CommandButton private to designated workbook?

    Hi,

    I am able to program command buttons to appear in the toolbar when a specific workbook is opened and it nicely disappears once the workbook is closed.

    My problem is that whilst that button having workbook is open and the user opens another excel workbook, the button appears there too and the code can be run without any problems there also
    How do I stop this? The button should ONLY appear on that workbook even if multiple workbooks are open. Is this possible?

    I put buttons in using the following code:

    Please Login or Register  to view this content.
    Last edited by EK1; 05-27-2010 at 09:15 AM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: How to make CommandButton private to designated workbook?

    Remove the toolbar in the Workbook_Deactivate event and enable it in the Workbook_Activate event.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    03-01-2010
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003
    Posts
    57

    Re: How to make CommandButton private to designated workbook?

    I call the above code from the workbook area of code with the following:

    Please Login or Register  to view this content.
    So I'm guessing instead of workbook_open I should change it to workbook_activate?

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: How to make CommandButton private to designated workbook?

    Not sure if the Workbook_activate event fires when a workbook opens. Try it. If not, put it in both places.

  5. #5
    Registered User
    Join Date
    03-01-2010
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003
    Posts
    57

    Re: How to make CommandButton private to designated workbook?

    I'm using the following code and it works perfectly. Exactly what I wanted. Thanks shg for the quick help.

    Please Login or Register  to view this content.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: How to make CommandButton private to designated workbook?

    Good job !

  7. #7
    Registered User
    Join Date
    03-01-2010
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003
    Posts
    57

    Re: How to make CommandButton private to designated workbook?

    Before I mark this solved, I noticed something else with these buttons.

    When someone modifies a cell, then clicks X in the corner to close then click CANCEL instead of SAVE or DO NOT SAVE.....the toolbar disappears. The before close method runs and the toolbar is gone. Is there any way to avoid this as it can get annoying.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: How to make CommandButton private to designated workbook?

    I don't see the Close event triggering if you press the Cancel button. Figure out what's happening.
    Last edited by shg; 05-26-2010 at 06:29 PM.

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,260

    Re: How to make CommandButton private to designated workbook?

    Check the Saved property of the workbook in your BeforeClose event and then do your own prompting as to whether they want to save. That way you will know whether or not to delete the toolbar.
    Remember what the dormouse said
    Feed your head

  10. #10
    Registered User
    Join Date
    03-01-2010
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003
    Posts
    57

    Re: How to make CommandButton private to designated workbook?

    This fixes the problem. Thanks to the interwebz.

    Please Login or Register  to view this content.

+ 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