jdjehanneman
New Member
- Joined
- Mar 23, 2021
- Messages
- 16
- Office Version
- 365
- Platform
- Windows
Hello,
I have a problem with my custom ribbon.
I would like Every time a file is opened, whether at Excel startup or via a control in a userform, to check whether the name of the file to be opened contains the string "Manage" and if so, make a custom tag visible.
The check should be done everytime a workbook is opened:
1. When the file was opened from within Excel
2. When a new file is created
2. When opening a file from a custom userform:
in the xml code I have put the following code :
In the VBA project I have created a module, RibbonModule:
When I open the file from the user form the check doesn't work because ThisWorkbook.Name is not the just opened workbook but the .xlam file controling the VBA:
The test is never met and my tab is not getting visible.
I hope I am clear enough, it is rather complex to explain.
Thank you in front for your help!
Johan
I have a problem with my custom ribbon.
I would like Every time a file is opened, whether at Excel startup or via a control in a userform, to check whether the name of the file to be opened contains the string "Manage" and if so, make a custom tag visible.
The check should be done everytime a workbook is opened:
1. When the file was opened from within Excel
2. When a new file is created
2. When opening a file from a custom userform:
VBA Code:
Private Sub bt_OpenManager_Click()
Dim strTemplateFilePath As String
Dim wb As Excel.Workbook
If listbox_Paths_Managers.ListIndex <> -1 Then
strTemplateFilePath = PATH_CICTOOLS_ADMIN & listbox_Paths_Managers.List(listbox_Paths_Managers.ListIndex)
FrmTemplateManager.Hide
Set wkb = Workbooks.Open(strTemplateFilePath)
End If
End Sub
in the xml code I have put the following code :
VBA Code:
<tab id="MyCustomTab2" label="CIC-Tools Templates" getVisible="GetVisible" tag="cictools_savetemplates">
In the VBA project I have created a module, RibbonModule:
VBA Code:
Dim Rib As IRibbonUI
Dim MyTag As String
' Callback for customUI.onLoad
' make tab cictools_savetemplates visible if opened filename contains "Manage" in the name
Sub RibbonOnLoad(ribbon As IRibbonUI)
Set Rib = ribbon
RibPointer = ObjPtr(ribbon)
If Contains = InStr(ThisWorkbook.Name, "Manage") > 1 Then
Call RefreshRibbon(Tag:="cictools_savetemplates")
End If
End Sub
'Called by sheet change event handler (module Sheet1) to make Excel recreate the ribbon
Sub RedoRib()
If Rib Is Nothing Then
Set Rib = GetRibbon(RibPointer)
Rib.Invalidate
MsgBox "The Ribbon handle was lost, Hopefully this is sorted now by the GetRibbon Function?. You can remove this msgbox, I only use it for testing"
Else
Rib.Invalidate
End If
End Sub
Sub GetVisible(control As IRibbonControl, ByRef visible)
If control.Tag Like MyTag Then
visible = True
Else
visible = False
End If
End Sub
Sub RefreshRibbon(Tag As String)
MyTag = Tag
If Rib Is Nothing Then
MsgBox "Error, restart your workbook"
Else
Rib.Invalidate
End If
End Sub
When I open the file from the user form the check doesn't work because ThisWorkbook.Name is not the just opened workbook but the .xlam file controling the VBA:
VBA Code:
InStr(ThisWorkbook.Name, "Manage")
The test is never met and my tab is not getting visible.
I hope I am clear enough, it is rather complex to explain.
Thank you in front for your help!
Johan