I've got an Excel 2007 VBA sc开发者_运维知识库ript 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?
Here is a snippet of the code that I've got loaded in 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.
Use the NewButton.Height and NewButton.Width to set the size of the button. Other properties can be found here
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:
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:
<?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 :)
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
For more info, look here
精彩评论