vba 在 Excel 2007 功能区按钮上添加更大的图标
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1664700/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adding Larger Icon On Excel 2007 Ribbon Button
提问by JustADude
I've got an Excel 2007 VBA script that adds a button to the ribbon, but unfortunately the icon is tiny. I tried several different FaceId's, but they all seemed to add tiny icon buttons. Is there a way to load in some of the newer 2007 size icons?
我有一个 Excel 2007 VBA 脚本,可以向功能区添加一个按钮,但不幸的是该图标很小。我尝试了几种不同的 FaceId,但它们似乎都添加了小图标按钮。有没有办法加载一些较新的 2007 尺寸图标?
Here is a snippet of the code that I've got loaded in ThisWorkbook:
这是我在 ThisWorkbook 中加载的代码片段:
Set NewButton = NewToolbar.Controls.Add(Type:=msoControlButton)
With NewButton
.FaceId = 752
.TooltipText = "Convert XLS Files to CSVs"
.OnAction = "XLSTOCSV"
Thanks for any insights about increasing the size of the icon.
感谢您提供有关增加图标大小的任何见解。
回答by TerrorAustralis
Use the NewButton.Height and NewButton.Width to set the size of the button. Other properties can be found here
使用 NewButton.Height 和 NewButton.Width 来设置按钮的大小。其他属性可以在这里找到
Hope this helps
希望这可以帮助
EDIT:
编辑:
Try this:
尝试这个:
Set NewButton= .Controls.Add(Type:=msoControlButton, Id:=YourFaceID)
I'm not sure, but that might do the auto sizing for you
我不确定,但这可能会为您自动调整大小
EDIT 2:
编辑2:
If it helps, try making a ribon if you are using buttons. The coding is really simple if you know basic XML. An example is this:
如果有帮助,如果您使用按钮,请尝试制作一个ribon。如果您了解基本的 XML,则编码非常简单。一个例子是这样的:
<?xml version="1.0" encoding="utf-8" ?>
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" >
<ribbon>
<tabs>
<tab id="myTab" label="New Tab">
<group id="group1" label="New Buttons">
<button id="MyButton" label="My Button" imageMso="HappyFace" size="large" onAction="myButton_ClickHandler" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
This creates a ribbon that looks like this:
这将创建一个看起来像这样的功能区:
Simple steps to getting this:
获取此信息的简单步骤:
- Open a new excel workbook
- Save it as an Excel Add In (*.xlam)
- Download this freeware: XML UI editor
- Paste the code above into it
- Save it
- Open Excel
- Go to Excel Options > Add ins > Go and tick whatever you called your addin
- Have fun with that :)
- 打开一个新的 Excel 工作簿
- 将其另存为 Excel 加载项 (*.xlam)
- 下载此免费软件: XML UI 编辑器
- 将上面的代码粘贴进去
- 保存
- 打开 Excel
- 转到 Excel 选项 > 加载项 > 转到并勾选您称为加载项的任何内容
- 玩得开心:)
A few notes on the code: The OnAction is the name of the sub in your excell addin that will be called when that button is clicked. The rest is pretty self explanatory
关于代码的一些说明: OnAction 是您的 Excel 插件中子项的名称,单击该按钮时将调用该子项。其余的都是不言自明的
For more info, look here
欲了解更多信息,请看这里