我已经使用提供的here电子表格创建了一个功能区,只要将宏分配给按钮,它就能很好地工作。但是,我希望在一组选项卡中包含配置详细信息,以使其始终可见,而不会占用Excel工作表空间。这是准备状态: Group in the custom tab
我有一个小宏来选择环境并识别图像中显示的各个字段的值。这是代码的样子:
Sub Change_Configuration()
Dim ConfigButton As Object
Dim Labeling As String
'SelectEnvironment.Show
Environment = "PROD"
If Environment = "QAS" Then
SourceSystem = "ABC"
TargetSystem = "DEF"
SourceSchema = "EFG"
TargetSchema = "GHI"
ElseIf Environment = "PROD" Then
SourceSystem = "IJK"
TargetSystem = "JKL"
SourceSchema = "LMN"
TargetSchema = "NOP"
End If
GetLabel ConfigButton, Labeling 'I do not know what to do here
End Sub
我知道Get Label是这样做的方法,但我对如何实现我想要实现的目标一无所知。当我打开excel文件并正确填充默认值(IF部分)时,我当前的GetLabel回调正常工作。我试图包括" Else"部分更新标签,但它不起作用。
原始代码:
Sub GetLabel(ByVal control As IRibbonControl, ByRef Labeling)
Select Case control.ID
Case "CustomTab": Labeling = "TEST_RIBBON"
Case "GroupE": Labeling = "Configuration Details"
Case "eButton01": Labeling = "Change Environment"
Case "eButton02": Labeling = "Selected Environment" & " - " & "QAS"
Case "eButton03": Labeling = "Source System" & " - " & "ABC"
Case "eButton04": Labeling = "Source Schema" & " - " & "DEF"
Case "eButton05": Labeling = "Target System" & " - " & "GHI"
Case "eButton06": Labeling = "Target Schema" & " - " & "IJK"
End Select
End Sub
当我打开excel时,所有标签都具有上面定义的值。
以下是修改后的代码(修改基于Change_Configuration宏更改标签的努力失败)。请注意,修改后的代码也不会在我的工作簿打开时抛出任何错误并正确显示值。
Sub GetLabel(ByVal control As IRibbonControl, ByRef Labeling)
If Environment = vbNullString Then
Select Case control.ID
Case "CustomTab": Labeling = "My Tab"
Case "GroupE": Labeling = "Configuration Details"
Case "eButton01": Labeling = "Change Environment"
Case "eButton02": Labeling = "Selected Environment" & " - " & "QAS"
Case "eButton03": Labeling = "Source System" & " - " & "ABC"
Case "eButton04": Labeling = "Source Schema" & " - " & "DEF"
Case "eButton05": Labeling = "Target System" & " - " & "EFG"
Case "eButton06": Labeling = "Target Schema" & " - " & "GHI"
End Select
Else
Select Case ConfigButton
Case "eButton02": Labeling = "Selected Environment" & " - " & Environment
Case "eButton03": Labeling = "Source System" & " - " & SourceSystem
Case "eButton04": Labeling = "Source Schema" & " - " & SourceSchema
Case "eButton05": Labeling = "Target System" & " - " & TargetSystem
Case "eButton06": Labeling = "Target Schema" & " - " & TargetSchema
End Select
End If
End Sub
非常感谢您的帮助。
-Jevich
答案 0 :(得分:1)
解决了它 - 在调整XML然后使用Invalidate函数之后,必须包含对Ribbon的onload回调。
答案 1 :(得分:0)
相关代码太少,无法帮助您完成
但请尝试改变:
Select Case ConfigButton
为:
Select Case control.ID
并观察会发生什么......