RE: VSTO 3 Word Add-In - ribbon XML does not refresh

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



With the help of Microsoft Support the following workaround was done similar
to your workaround.

1. Declared public variable in ThisAddIn:
Public m_ribbon As Ribbon

2. Changed the CreateRibbonExtensibilityObject function to:
m_ribbon = New Ribbon()
Return m_ribbon

3. Changed the scope of the variable ribbon as Office.IRibbonU to public
4. Implemented Application_DocumentOpen event to invalidate control:

Private Sub Application_DocumentOpen(ByVal Doc As
Microsoft.Office.Interop.Word.Document) Handles Application.DocumentOpen
m_ribbon.ribbon.InvalidateControl("rxBtnCheckDocument")
End Sub

Ribbon now works for every document that is opened.

"Virtualware" wrote:


Hi, I'm not suer if you solve the issue of the subsequent refresh
I'm using MS-Access and have a similar problem.

the way I solve it was as shown below:
Public gobjRibbon As IRibbonUI
Public gobjRibbon1 As IRibbonUI

Public Sub CallbackOnLoad(ribbon As IRibbonUI)
' Cache a copy RibbonUI
Set gobjRibbon = ribbon
End Sub

Public Sub CallbackOnLoad1(ribbon As IRibbonUI)
' Cache a copy RibbonUI
Set gobjRibbon1 = ribbon
End Sub

then I just called from the xmlcode CallbackOnLoad1




"SMutlu" wrote:

I'm having trouble getting my custom buttons to be visible or not visible
based on the active document's template. I've set the getVisible method for
each group of buttons in the XML file to a function that checks the
document's template and if the name is the same as the XML group id then I do
a ribbon.InvalidateControl(group.id) and the function returns True which
should make the group visible. When I test this by opening documents based
on different templates it works for the first few documents but not
subsequent ones. My code and XML is this:-

Public Function IsCustomGroupVisible(ByVal group As Office.IRibbonControl)
As Boolean
Return WhichTemplate(TryCast(group.Context, Word.Window), group)
End Function

Private Function WhichTemplate(ByVal Window As Word.Window, ByVal group As
Office.IRibbonControl) As Boolean

If Window Is Nothing Then
Return False
Else
Dim doc As Word.Document = DirectCast(Window.Parent,
Word.Document)
Dim docTemplate = CType(doc.AttachedTemplate, Word.Template)

'get just the template name minus the extension
Dim iValue As Integer = InStr(docTemplate.Name, ".",
CompareMethod.Text)
Dim strTemplate As String = Mid(docTemplate.Name, 1, iValue - 1)
Dim iStrCompare As Integer

iStrCompare = StrComp(strTemplate, group.Id, CompareMethod.Text)

MsgBox("Document Template is " & strTemplate & vbNewLine &
"Ribbon Group is " & group.Id _
& vbNewLine & "Document name is " & doc.Name)

If iStrCompare = 0 Then
Try
ribbon.InvalidateControl(group.Id)
Return True
Catch ex As Exception
MsgBox(ex)

End Try

Else
Return False
End If
End If
End Function

<group id="Letter" label="Letter" getVisible="IsCustomGroupVisible">
<button id="btnCopiedTo"
imageMso="CopyToPersonalContacts"
onAction="btnCopiedTo_Click"
screentip="Add ccs/bccs"
supertip="Add people to copy this letter to"
label="Add copies"
size="large" />

<button id="btnSendAsFax"
imageMso="FileInternetFax"
onAction="btnSendAsFax_Click"
screentip="Send as a fax"
supertip="Send this letter as a fax"
label="Send as a fax"
size="large" />
</group>

<group id="Fax" label="Fax" getVisible="IsCustomGroupVisible">
<button id="btnCopyFaxTo"
imageMso="Copy"
onAction="btnCopyFaxTo_Click"
screentip="Copy fax to another party"
supertip="Add people to copy this fax to"
label="Add copies"
size="large" />
</group>

.


Quantcast