ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Call a callback to toggle a tab visible/hidden? (https://www.excelbanter.com/excel-programming/409848-call-callback-toggle-tab-visible-hidden.html)

XP

Call a callback to toggle a tab visible/hidden?
 
I want to be able to toggle a Tab visible/hidden on the Ribbon based upon the
contents of a cell.

I have the tab written in XML and the following call back works, but only
each time the file is closed and reopened. How can I make this more fluid so
it updates immediately without having to close and reopen the file? Is there
a way I can call the Callback below to make it run again?

Sub getVisibleCallback(control As IRibbonControl, ByRef visible As Variant)
Dim sShow As String
sShow = [A1].FormulaR1C1
If UCase(sShow) < "" Then
visible = True
Else
visible = False
End If
End Sub


Melanie Breden[_3_]

Call a callback to toggle a tab visible/hidden?
 
Hi,

"XP" schrieb:
I have the tab written in XML and the following call back works, but only
each time the file is closed and reopened. How can I make this more fluid so
it updates immediately without having to close and reopen the file? Is there
a way I can call the Callback below to make it run again?


look at the following example:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
onLoad="rx_onLoad"
<ribbon
<tabs
<tab id="tab_1" label="Custom tab" getVisible="getVisibleCallback" /
</tabs
</ribbon
</customUI

' Modul1
Public objRibbon As IRibbonUI

Public Sub rx_onLoad(ribbon As IRibbonUI)
Set objRibbon = ribbon
End Sub

Public Sub getVisibleCallback(control As IRibbonControl, ByRef visible As Variant)
visible = Worksheets("Sheet1").Range("A1").Value < ""
End Sub

' Codemodule Sheet1
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(0, 0) < "A1" Then Exit Sub
objRibbon.InvalidateControl "tab_1"
End Sub


Mit freundlichen Grüssen
Melanie Breden

- Microsoft MVP für Excel -


XP

Call a callback to toggle a tab visible/hidden?
 
Hi Melanie,

Excellent; thank you so much!!!

Regards from USA

"Melanie Breden" wrote:

Hi,

"XP" schrieb:
I have the tab written in XML and the following call back works, but only
each time the file is closed and reopened. How can I make this more fluid so
it updates immediately without having to close and reopen the file? Is there
a way I can call the Callback below to make it run again?


look at the following example:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
onLoad="rx_onLoad"
<ribbon
<tabs
<tab id="tab_1" label="Custom tab" getVisible="getVisibleCallback" /
</tabs
</ribbon
</customUI

' Modul1
Public objRibbon As IRibbonUI

Public Sub rx_onLoad(ribbon As IRibbonUI)
Set objRibbon = ribbon
End Sub

Public Sub getVisibleCallback(control As IRibbonControl, ByRef visible As Variant)
visible = Worksheets("Sheet1").Range("A1").Value < ""
End Sub

' Codemodule Sheet1
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(0, 0) < "A1" Then Exit Sub
objRibbon.InvalidateControl "tab_1"
End Sub


Mit freundlichen Grüssen
Melanie Breden

- Microsoft MVP für Excel -



All times are GMT +1. The time now is 09:08 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com