VBA 更改 运行 宏上多个功能区按钮标签的代码
VBA code to change label of multiple ribbon buttons on running a macro
我已经使用 here 提供的传播sheet 创建了一个功能区,只要它是关于为按钮分配宏,它就很好用。但是,我想在一组选项卡中包含配置详细信息,以使其始终可见,而不会占用 excel sheet 空间。这是未来的状态:
Group in the custom tab
我有一个小宏 select 环境并识别图像中显示的各个字段的值。代码如下所示:
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
我知道获取标签是实现它的方法,但我不知道如何实现我想要实现的目标。当我打开 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
非常感谢您的帮助。
-耶维奇
相关代码太少,无法确保帮助您完成
但试着改变一下:
Select Case ConfigButton
至:
Select Case control.ID
看看会发生什么...
已解决 - 在调整 XML 和 Invalidate 函数后必须包含功能区的 onload 回调。
我已经使用 here 提供的传播sheet 创建了一个功能区,只要它是关于为按钮分配宏,它就很好用。但是,我想在一组选项卡中包含配置详细信息,以使其始终可见,而不会占用 excel sheet 空间。这是未来的状态: Group in the custom tab
我有一个小宏 select 环境并识别图像中显示的各个字段的值。代码如下所示:
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
我知道获取标签是实现它的方法,但我不知道如何实现我想要实现的目标。当我打开 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
非常感谢您的帮助。
-耶维奇
相关代码太少,无法确保帮助您完成
但试着改变一下:
Select Case ConfigButton
至:
Select Case control.ID
看看会发生什么...
已解决 - 在调整 XML 和 Invalidate 函数后必须包含功能区的 onload 回调。