使用VBA更改命令栏按钮属性 [英] Changing Command Bar Buttons properties using VBA

查看:266
本文介绍了使用VBA更改命令栏按钮属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Excel中使用CustomUI编辑器创建了一个自定义功能区,它正常工作。


我想在功能区上添加一个功能单击,它会一直突出显示,直到单击下一个按钮。我正在使用下面的VBA代码循环执行命令栏,但是在循环浏览
  命令栏按钮对象时出现问题。  


我认为VBA是这样做的方式(而不是UI编辑器中的XML),所以对CommandBarButton对象的任何帮助都非常感谢。


Dim bar As CommandBar


Dim btn As CommandBarButton


For Application.CommandBars中的每个栏位


    Debug.Print bar.Name


    'For Each btn In ????


    'Debug.Print btn.Name


    '下一步


下一步


提前致谢


Roy

解决方案

功能区控件不是CommandBar控件的一部分。 XML是您需要查看的内容,您可以使用UI编辑器执行此操作,但还有其他方法。为了帮助您入门 

< customUI xmlns =" http://schemas.microsoft.com/office/2006/01/customui" > 
< ribbon>
< tabs>
< tab idMso =" TabHome" >
< group idMso =" GroupClipboard" >
< toggleButton
id =" Togglebutton1"
label =" Togglebutton1"
getPressed =" Togglebutton1_getPressed"
onAction =" Togglebutton1_onAction" />
< / group>
< / tab>
< / tabs>
< / ribbon>
< / customUI>


'VBA回调


Public Sub Togglebutton1_getPressed (控制为IRibbonControl,ByRef returnsVal)
'
'getPressed回调代码。功能区控件toggleButton
'

结束Sub

Public Sub Togglebutton1_onAction(控制为IRibbonControl,ByRef cancelDefault)
'
'onAction代码打回来。功能区控件toggleButton
'

结束子





I have a custom ribbon in excel created using CustomUI editor, which is working as it should.

I want to add a feature in that once a button on the ribbon is clicked, it remains highlighted until the next button is clicked. I am using the VBA code below to loop through the command bars, but having a problem the looping through  Command Bar Buttons objects.  

I think VBA is the way to do this (and not the XML in the UI editor), so any help with the CommandBarButton object is much appreciated.

Dim bar As CommandBar

Dim btn As CommandBarButton

For Each bar In Application.CommandBars

    Debug.Print bar.Name

    'For Each btn In ????

    'Debug.Print btn.Name

    'Next

Next

Thanks in advance

Roy

解决方案

Ribbon controls are not part of CommandBar controls. XML is what you need to look at, which you can do with the UI editor though there are other ways. To get you started 

<customUI  xmlns="http://schemas.microsoft.com/office/2006/01/customui" >
	<ribbon >
		<tabs >
			<tab  idMso="TabHome" >
				<group  idMso="GroupClipboard" >
					<toggleButton 
						id="Togglebutton1"
						label="Togglebutton1"
						getPressed="Togglebutton1_getPressed"
						onAction="Togglebutton1_onAction"/>
				</group >
			</tab >
		</tabs >
	</ribbon >
</customUI >

' VBA callbacks


Public Sub Togglebutton1_getPressed(control as IRibbonControl, ByRef returnedVal)
'
' Code for getPressed callback. Ribbon control toggleButton
'

End Sub

Public Sub Togglebutton1_onAction(control as IRibbonControl, ByRef cancelDefault)
'
' Code for onAction callback. Ribbon control toggleButton
'

End Sub



这篇关于使用VBA更改命令栏按钮属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆