我在 MS Word 中生成了一個自定義選項卡,它構成了檔案檢查程序的一部分。在該程序開始時,會打開一個用戶表單,您可以添加 x 數量的電子郵件以供稍后在檢查程序中使用。
這個想法是讓自定義選項卡動態更新以顯示相應的編號。在用戶表單中輸入的電子郵件的按鈕。
據我所知,我已經編輯了 XML 并具有所有必需的功能,但是當我在用戶表單完成后嘗試呼叫 Reintialise() 使 UI 無效時:
Public MyRibbon As IRibbonUI
Public Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef destination As Any, ByRef source As Any, ByVal length As Long)
Public Sub MyAddInInitialize(Ribbon As IRibbonUI)
Set MyRibbon = Ribbon
ActiveDocument.Variables.Add("RibbonAddress") = CStr(ObjPtr(Ribbon))
End Sub
Function GetRibbon(ByVal lRibbonPointer As LongPtr) As Object
Dim objRibbon As Object
CopyMemory objRibbon, lRibbonPointer, LenB(lRibbonPointer)
Set GetRibbon = objRibbon
Set objRibbon = Nothing
End Function
Sub btnCheck_getVisible(control As IRibbonControl, ByRef returnedVal)
'If condition to toggle getVisible callback from VBA that works
End Sub
Sub Reintialise()
If MyRibbon Is Nothing Then
Set MyRibbon = GetRibbon(ActiveDocument.Variables("RibbonAddress"))
MyRibbon.Invalidate
Else
MyRibbon.Invalidate
End If
End Sub
I receive the error 'Run-time error '5825':' Object has been deleted' when running this version of the code where the ribbon information is attempted to be written to a variable. If in sub reintialise it just has MyRibbon.Invalidate I get the error 'Run-time error '91': Object Variable or With Block Variable not set' which is obviously from MyRibbon not being defined.
I have attempted to recall MyAddInIntialise to redefine the object MyRibbon as well as storing 'Ribbon' as a document variable to call later but none of my methods have worked thus far.
Example of XML button:
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="MyAddInIntialize">
<ribbon>
<tabs>
<tab id="customTab" label="Checking" insertAfterMso="TabReviewWord">
<group id="startGov" label="Governance Progress Overview">
<button id="emailCheck1" label="Send Document to First Checker" size="large"
onAction="send_email" getVisible="btnCheck_getVisible"
getEnabled="btn_trigger" imageMso="AppointmentColor1"/>
</group>
</tab>
</tabs>
</ribbon>
uj5u.com熱心網友回復:
您是否收到任何功能區 UI 錯誤?
默認情況下,如果加載項嘗試操作 Microsoft Office 用戶界面 (UI) 并失敗,則不會顯示錯誤訊息。但是,您可以將 Microsoft Office 應用程式配置為顯示與 UI 相關的錯誤訊息。您可以使用這些訊息來幫助確定不顯示自定義功能區的原因,或顯示功能區但未顯示控制元件的原因。
要顯示 VSTO 插件用戶界面錯誤,您需要:
- 啟動應用程式。
- 單擊
File選項卡。 - 單擊
Options。 - 在類別窗格中,單擊
Advanced。 - 在詳細資訊窗格中,選擇
Show VSTO Add-in user interface errors,然后單擊OK。
有關詳細資訊,請參閱如何:顯示加載項用戶界面錯誤。
確保MyAddInInitializeOffice 應用程式呼叫的方法和物件已正確初始化。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/439845.html
上一篇:MSAccessVBA:向表中添加了列,但現在SQL“INSERTINTO”不再起作用
下一篇:鎖定特定作業表中的單元格
