Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-23-2023, 12:24 PM
Ddadoo57 Ddadoo57 is offline I lose my instance of IRibbonUI Windows 11 I lose my instance of IRibbonUI Office 2021
Advanced Beginner
I lose my instance of IRibbonUI
 
Join Date: Feb 2023
Posts: 90
Ddadoo57 is on a distinguished road
Default I lose my instance of IRibbonUI

Good evening,

In a custom bar in word, I have a group of 6 togglebuttons. It is only the button I click on that remains selected. I handled this with the getPressed and onAction callbacks.

My CustomUI is loaded as follows:

Public objRibbon As IRibbonUI
Sub R_OnLoad(ribbon As IRibbonUI)
Set objRibbon = ribbon

objRibbon.ActivateTab ("TC_Tab")
...


End Sub

Everything works fine, except that from time to time, I lose objRibbon, my instance of IRibbonUI, and a click on one of the togglbuttons causes an error 91 (object not defined)

Has anyone encountered this problem? Is there any way to write the object instance in memory?

Sincerely,
David


Translated with www.DeepL.com/Translator (free version)
Reply With Quote
  #2  
Old 02-23-2023, 04:18 PM
Guessed's Avatar
Guessed Guessed is offline I lose my instance of IRibbonUI Windows 10 I lose my instance of IRibbonUI Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,163
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

When you edit the vba code in a template it often (always?) kills off the ribbon instance for that template. The easy fix is to close and reopen that template.

If you wanted to develop a method of being able to recreate the ribbon instance because you can't live with the easy fix, you can get some excellent guidance from this link. That code is for Excel and stores a Long value in a place that won't work in Word but the code should be easily adaptable for a Word solution.
Refresh Ribbon UI In Your Custom Excel Add-in
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 02-24-2023, 12:02 AM
Ddadoo57 Ddadoo57 is offline I lose my instance of IRibbonUI Windows 11 I lose my instance of IRibbonUI Office 2021
Advanced Beginner
I lose my instance of IRibbonUI
 
Join Date: Feb 2023
Posts: 90
Ddadoo57 is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
When you edit the vba code in a template it often (always?) kills off the ribbon instance for that template. The easy fix is to close and reopen that template.
yes I had noticed

Quote:
Originally Posted by Guessed View Post
If you wanted to develop a method of being able to recreate the ribbon instance because you can't live with the easy fix, you can get some excellent guidance from this link. That code is for Excel and stores a Long value in a place that won't work in Word but the code should be easily adaptable for a Word solution.
Refresh Ribbon UI In Your Custom Excel Add-in
Thanks a lot Guessed, I will adapt this code!
Best regards,
David
Reply With Quote
  #4  
Old 02-24-2023, 04:38 AM
Ddadoo57 Ddadoo57 is offline I lose my instance of IRibbonUI Windows 11 I lose my instance of IRibbonUI Office 2021
Advanced Beginner
I lose my instance of IRibbonUI
 
Join Date: Feb 2023
Posts: 90
Ddadoo57 is on a distinguished road
Default

I just tried to adapt for Word, the Excel code that Guessed proposes in the link.
However, I have a problem, Word crashes at the line :
CopyMemory myRibbon, lRibbonPointer, LenB(lRibbonPointer) in the Function GetRibbon(...)

The application crashes, then restarts the recovered document in read-only mode.


Here are the lines I modified to adapt them to Word

I added in declaration :
Private Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As LongPtr)

Then in: Sub RibbonLoaded_MyCustomAddin(ribbon As IRibbonUI)
I replaced : ThisWorkbook.Names.Add Name:="RibbonID", RefersTo:=StoreRibbonPointer
with : ThisDocument.Variables("RibbonID") = StoreRibbonPointer

in : Sub RefreshRibbon()
I replaced: Set objRibbon = GetRibbon(Replace(ThisWorkbook.Names("TSGRibbonID" ).RefersTo, "=", ""))
by : Set objRibbon = GetRibbon(Replace(ActiveDocument.Variables("Ribbon ID"), "=", ""))


Does anyone have the skills to help me? Here I am sinking

Sincerely,
David
Reply With Quote
  #5  
Old 02-24-2023, 06:55 AM
Ddadoo57 Ddadoo57 is offline I lose my instance of IRibbonUI Windows 11 I lose my instance of IRibbonUI Office 2021
Advanced Beginner
I lose my instance of IRibbonUI
 
Join Date: Feb 2023
Posts: 90
Ddadoo57 is on a distinguished road
Default

Here is a possible solution to adapt it. It seems to work (see in time)

Here are the lines I modified to adapt them to Word

So I put in the declaration :
Private Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As LongPtr)

In: Sub RibbonLoaded_MyCustomAddin(ribbon As IRibbonUI)
ThisDocument.Variables("RibbonID") = StoreRibbonPointer
ThisDocument.Saved = True


In: Sub RefreshRibbon()
I deleted: 'Dim objRibbon As Object
I put this: Set objRibbon = GetRibbon(Replace(ActiveDocument.Variables("Ribbon ID"), "=", ""))

Now I can call "Call RefreshRibbon" it seems where I want, in my case in the Callback of onAction of my ToggleButtons. For the moment it seems to work and moreover I can modify on the fly the vba code of the Ribbon without it crashing either! (
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Upgrading from Trial Version - don't want to lose notebooks! HyperNote OneNote 0 05-01-2017 04:24 AM
I lose my instance of IRibbonUI Font will not lose Italic. Corruption? Ulodesk Word 2 07-25-2016 06:01 AM
How can I embed a word document so I don't lose the links therein Dracven Outlook 2 03-31-2014 04:02 AM
How do I lose these dotted lines? jlumbtx Word 4 11-09-2013 10:29 PM
I lose my instance of IRibbonUI Lose formatting when copying text shadox Excel 1 07-31-2012 08:50 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:35 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft