+ Reply to Thread
Results 1 to 10 of 10

Creating an addins menu bar on a specific session/sheet

  1. #1
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,343

    Creating an addins menu bar on a specific session/sheet

    I am creating a menu bar using code like the below in excel 2013 and 2010 in an addin

    Please Login or Register  to view this content.
    is there a way for me to specify which sheet (session) the menu will appear in?

    the issue is that I have a temporary excel file I want it to be assigned to but it keeps assigning it to another sheet.

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,009

    Re: Creating an addins menu bar on a specific session/sheet

    Here is sample code creating a menu bar add-in that activates when the workbook is opened and deactivates when the workbook is closed. Couldn't this be done for your needs by placing the code into Worksheet Initialize or Activate ... then Worksheet Deactivate ?

    I haven't tested the code.

    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,343

    Re: Creating an addins menu bar on a specific session/sheet

    Yes that is pretty similar to how I currently have it working.

    Unfortunately this problem occurs in a specific situation where Another application (SAP) is opening an excel file as a temporary file. When excel tries to assign the menu by default it is putting it in the wrong session (maybe that is an error on SAP's behalf but i need to work around it). This was fine for 2010 because excel opened multiple files in a single session - now however with 2013 there is an issue.

    I was hoping that I could override the default by specifying the session or the file that the menu should be associated with. Or another option is to create the menus in an add-in that i have installed in all the users computers (which of course does display as it displays in all excel sessions) and then maybe hide it and unhide it when this sheet is loaded

    ie set my
    Please Login or Register  to view this content.
    then in the sheet I open set
    Please Login or Register  to view this content.
    However I am still having trouble referring to the command bar... maybe it is still looking for it in the wrong session.

  4. #4
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,009

    Re: Creating an addins menu bar on a specific session/sheet

    Please Login or Register  to view this content.
    Change to

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

  5. #5
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,009

    Re: Creating an addins menu bar on a specific session/sheet

    Found this on LINK

    WHAT’S DIFFERENT IN EXCEL 2013 AND EXCEL 2016?
    If you’ve used VBA to work with shortcut menus in Excel 2007 or earlier, you need to be aware of a significant change.

    In the past, if your code modified a shortcut menu, that modification was in effect for all workbooks. For example, if you added a new item to the Cell right-click menu, that new item would appear when you right-clicked a cell in any workbook (plus other workbooks that you open later on). In other words, shortcut-menu modifications were made at the application level.

    Excel 2013 and Excel 2016 use a single document interface, and that affects shortcut menus. Changes that you make to shortcut menus affect only the active workbook window. When you execute the code that modifies the shortcut menu, the shortcut menu for windows other than the active window will not be changed. This is a radical departure from how things used to work.

    Another twist: If the user opens a workbook (or creates a new workbook) when the active window displays the modified shortcut menu, the new workbook also displays the modified shortcut menu. In other words, new windows display the same shortcut menus as the window that was active when the new windows were opened.

    Bottom line: In the past, if you opened a workbook or add-in that modified shortcut menus, you could be assured that the modified shortcut menus would be available in all workbooks. You no longer have that assurance.
    As I understand what the author is saying, your challenge is due to Excel versions earlier to 2013 / 2016. If he is accurate, seems like its time to upgrade versions ?
    Last edited by Logit; 11-06-2016 at 08:56 PM.

  6. #6
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,343

    Re: Creating an addins menu bar on a specific session/sheet

    Quote Originally Posted by Logit View Post
    Found this on LINK

    As I understand what the author is saying, your challenge is due to Excel versions earlier to 2013 / 2016. If he is accurate, seems like its time to upgrade versions ?
    yes I think this is exactly the issue...

    Update my version of SAP? Yes that would be nice but sadly that would be prohibitively expensive.
    The excel on the other hand - the update is apparently the thing causing problem. But of course people want to update that and other systems due to support running out for old versions of software etc.

    I tried playing around with

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    etc - but no luck...

    I have managed to get pretty close... I can create the bar using my addin, and then unhide it when required. But the tool bar needs to link to macros in the sheet i open and i don't know the name of that sheet until it is open (which will be some jumble of letters and numbers like ~SAP23423542) so i don't know how to assign it's macros to the toolbar. (otherwise I'd just write "~SAP23423542!macroA").

    If I try to assign the buttons after the sheet is open (i.e. when I can tell what the file name is by using the activesheet.name) i seem to run into my same problem of not being about to talk properly to the toolbar - it complains as follows "method add of object 'commandbarcontrols' failed"

    BTW I really appreciate having another mind look at this.
    Last edited by scottiex; 11-06-2016 at 10:45 PM.

  7. #7
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,009

    Re: Creating an addins menu bar on a specific session/sheet

    I would presume there is a workaround out there somewhere but (admittedly) coding for that is above my knowledge level.

    Perhaps one of the gurus here will assist.

    Wish I could more for you.

    ps: would love to visit your country.

  8. #8
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Creating an addins menu bar on a specific session/sheet

    Hi.

    I inagine your toolbars could simply run macros that do something along these lines:

    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  9. #9
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,343

    Re: Creating an addins menu bar on a specific session/sheet

    Unfortunately the toolbar doesn't know the name of the temporary file that will be there when it creates the toolbar for the add in, and if it is run form the temporary file it seems to think I want any tool bar it adds added to a different sheet, and it cant seem to edit the existing add-in toolbar. Although its possible I'm doing something wrong there.

    However, I have a workaround that seems to be working - I have entered all the code from the temporary files in the addin (quite a bit of code) and the user can select in the add in what tool bar they want to show. Not really as neat as talking to the macros in the temporary file - But this seems to be working so far.

  10. #10
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Creating an addins menu bar on a specific session/sheet

    The add-in does not need to know the name of the file. It simply contains several macros that do nothing more than call Application.Run with the name of the macro in the temporary file. The activeworkbook.name part will get the name of the file at run time, whatever it happens to be.

+ 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. Replies: 1
    Last Post: 07-01-2015, 06:46 AM
  2. [SOLVED] Losing a custom menu bar within Windows menu bar when new excel session is opened.
    By SCACCHIA in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 11-17-2014, 04:34 PM
  3. [SOLVED] Creating a search method in an excel sheet to identify things according to a specific id.
    By Moh13 in forum Excel Programming / VBA / Macros
    Replies: 28
    Last Post: 10-02-2013, 11:40 PM
  4. Need Help Hyperlinking to a Batch File
    By danaconda84 in forum Excel General
    Replies: 0
    Last Post: 09-04-2013, 01:32 PM
  5. Replies: 0
    Last Post: 04-27-2012, 12:43 PM
  6. Replies: 0
    Last Post: 04-21-2011, 09:20 AM
  7. Start a new session when a session is already opend
    By MD in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-17-2005, 01:50 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