+ Reply to Thread
Results 1 to 5 of 5

Issue with sequence of events: Workbook_open, Workbook_sheetActivate, and custom Ribbon

  1. #1
    Registered User
    Join Date
    01-23-2013
    Location
    Repentigny, Québec
    MS-Off Ver
    Excel 2013
    Posts
    15

    Issue with sequence of events: Workbook_open, Workbook_sheetActivate, and custom Ribbon

    Hi all,

    I created a custom ribbon which changes based on the worksheet based on information I got from Ron de Bruin. It took me sometime to figure it out as I kept getting an error which not directly related to the Ribbon customization per se.

    When the workbook is opened, everything works fine. The issue occurs when I open the workbook. Upon opening the workbook, I use Workbook_open to perform some actions in the workbook but I also use Workbook_SheetActivate to change the customized Ribbon on the fly.

    I believe the issue is that when workbook_open() is executed, the customized ribbon is not loaded yet. Upon opening the workbook, Rib = Nothing. Thus, my question is how can I handle the Workbook_SheetActivate to be executed after the workbook_open or similarly is there a way to force loading the customized ribbon as a first set in workbook_open().


    In This.Workbook:


    Please Login or Register  to view this content.

    Please Login or Register  to view this content.

    Please Login or Register  to view this content.


    Kindest regards,

    Dominic.

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Issue with sequence of events: Workbook_open, Workbook_sheetActivate, and custom Ribbo

    If you think it is a timing issue, have you tried inserting a delay at the begiinning of your ribbon code?
    Please Login or Register  to view this content.
    This would give a 2 second delay before executing the rest of the code.

    Or as you alluded to in your post, call the ribbon sub from your Workbook_Open event.
    Last edited by JLGWhiz; 09-11-2020 at 03:54 PM.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Registered User
    Join Date
    01-23-2013
    Location
    Repentigny, Québec
    MS-Off Ver
    Excel 2013
    Posts
    15

    Re: Issue with sequence of events: Workbook_open, Workbook_sheetActivate, and custom Ribbo

    Quote Originally Posted by JLGWhiz View Post
    If you think it is a timing issue, have you tried inserting a delay at the begiinning of your ribbon code?
    Please Login or Register  to view this content.
    This would give a 2 second delay before executing the rest of the code.

    Or as you alluded to in your post, call the ribbon sub from your Workbook_Open event.

    Thank you for your response! I will try this to check if it would have solved the problem. However, what I ended up doing was to create a global variable to control whether Workbook_open() is executed. This appears to be doing the trick.




    Please Login or Register  to view this content.


    Kindest regards,

    Dominic.

  4. #4
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Issue with sequence of events: Workbook_open, Workbook_sheetActivate, and custom Ribbo

    Thanks for the feedback,
    Regards, JLG

  5. #5
    Registered User
    Join Date
    01-23-2013
    Location
    Repentigny, Québec
    MS-Off Ver
    Excel 2013
    Posts
    15

    Re: Issue with sequence of events: Workbook_open, Workbook_sheetActivate, and custom Ribbo

    Hi all,

    This is a follow up on the issue which I is now fixed (so I believe). I wanted to create a ribbon that would update based on the worksheet activated. I faced two problems:
    1. 1. Upon opening the workbook, there were actions prior loading the ribbon which was issue
    2. 2. Any VBA code error caused an issue with the customized ribbon because Excel was losing the ribbon id


    I was able to fix first problem by creating a global variable as a flag. Nevertheless, this fix was not general enough. However, I was able to find a fix for the second one that was developed by RoryA (MrExcel MVP. Moderator) with a workbook made available by WernerGg. I cannot paste the link, but you can find the discussion by conducting a search for "How to preserve or regain the Id of my custom ribbon UI?"

    The basic idea is that Excel some times loses the ribbon id. The approach uses a cell in the workbook to store the ribbon id which can be used to refresh the ribbon. However, the solution proposed needed some tweaking because it requires to be updated for 64 bit version of Excel.


    Module ObjectStore


    Please Login or Register  to view this content.


    Please Login or Register  to view this content.

    Kindest regards,

    Dominic.
    Last edited by dommit64; 10-26-2020 at 05:44 PM. Reason: The code did not appear properly tagged

+ 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. [SOLVED] Worksheet_Activate & Workbook_SheetActivate events error 1004 when several sheets selected
    By Daishiknyte in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-05-2019, 05:39 PM
  2. [SOLVED] Application.Enable Events Property stopping Workbook_Open() Event
    By Sc0ut in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-07-2016, 05:09 PM
  3. Issue with Workbook_SheetActivate
    By KiwiRickToo in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-27-2016, 08:27 AM
  4. [SOLVED] An alternative to the Add-Ins ribbon tab - Global Custom Ribbon Tab by Ken Puls
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-16-2014, 10:01 PM
  5. Excel 2007 workbook_open events are not working
    By ljoseph in forum Excel General
    Replies: 1
    Last Post: 05-11-2010, 01:51 PM
  6. [SOLVED] Using Workbook_AddinInstall -vs- Workbook_Open Events
    By Bill Schanks in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-23-2005, 12:25 AM
  7. [SOLVED] Workbook_Open - Multiple Events not all working
    By Punsterr in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-06-2005, 03:05 AM

Tags for this Thread

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