S
SMutlu
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>
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>