View Full Version : Ribbon run-time error 5825
NarayanR
01-09-2021, 11:51 AM
Hi Greg/All,
Good Day. I am new to VBA and have been handling VBA Macro(Word-Addin). My Macro is designed as Word Ribbons in word document and i have been facing similar run-time error '5825' in Run-time and the Ribbon fades away. I have tried to load the .dotm module over Visual basic editor and ran the module and coudnt see any errors during debugging, but the word program closes abruptlly as error. Please can kindly help me to resolve this error.
gmaxey
01-09-2021, 01:22 PM
Are you losing the reference to your ribbon object?
You might try some variation of this:
Option Explicit
#If VBA7 Then
  Public Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef destination As Any, ByRef source As Any, ByVal length As Long)
#Else
  Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef destination As Any, ByRef source As Any, ByVal length As Long)
#End If
Public p_oRibbon As IRibbonUI
Public Sub OnLoad(oRibbon As IRibbonUI)
  Set p_oRibbon = oRibbon
  ThisDocument.Variables("RXPointer") = ObjPtr(oRibbon)
  ThisDocument.Saved = True
lbl_Exit:
  Exit Sub
End Sub
Function GetRibbon() As Object
#If VBA7 Then
  Dim lngRibPtr As LongPtr
  lngRibPtr = CLngPtr(ThisDocument.Variables("RXPointer"))
#Else
  Dim lngRibPtr As Long
  lngRibPtr = CLng(ThisDocument.Variables("RXPointer"))
#End If
  Dim oRibbon As Object
  CopyMemory oRibbon, lngRibPtr, LenB(lngRibPtr)
  Set GetRibbon = oRibbon
  Set oRibbon = Nothing
lbl_Exit:
  Exit Function
End Function
Sub AutoClose()
  ClearRibbonMemory
lbl_Exit:
  Exit Sub
End Sub
Sub ClearRibbonMemory()
  Set p_oRibbon = Nothing
lbl_Exit:
  Exit Sub
End Sub
Sub Test()
   If p_oRibbon Is Nothing Then Set p_oRibbon = GetRibbon
   p_oRibbon.InvalidateControl "G3EditBox001"
End Sub
macropod
01-10-2021, 01:29 AM
Cross-posted at: https://chandoo.org/forum/threads/error-5825-object-has-been-deleted.45578/
Please read VBA Express' policy on Cross-Posting in Rule 3: http://www.vbaexpress.com/forum/faq.php?faq=new_faq_item#faq_new_faq_item3
NarayanR
01-10-2021, 01:00 PM
Thank you Greg for your inputs.Yes, Ribbon referrnces fades aways and the VBA Error '5825' appears. While debugging the code, i could see the 'Object variable not set, 91 Error' for the object(see the attachment), not sure if this is the cause for Error '5825'. Please check and let me know the steps to post my .dotm code so you can verify and assist me.
NarayanR
02-03-2021, 04:10 PM
Hi Greg,
Good Day. With VBA Code at Design time, have been facing VBA Error '91' while debugging. But i am unable to figure out the exact line of code that causes the error. Please assist.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.