View Single Post
 
Old 02-24-2023, 04:38 AM
Ddadoo57 Ddadoo57 is offline Windows 11 Office 2021
Advanced Beginner
 
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