英文:
How to change the font size consistently on ActiveX command buttons
问题
所以我有一个包含约15个ActiveX命令按钮的Excel工作簿,这些按钮被选中来运行宏。它们的高度和宽度都相同,但我有一个子程序持续运行,始终将它们的高度和宽度设置为一致的值。这是因为有时按下按钮时它们的大小会开始变化。
最近,我们注意到有时字体大小也会不断减小,所以我想将它们的字体大小硬编码到宏中。
我尝试使用类似CommandButton1.font.size = 15
的函数。这个方法起效了,但当我将它应用到每个按钮时,相同的字体大小最终在每个按钮上显示出不同的效果?我以为这可能是由于按钮的尺寸问题,但这不可能是原因,因为这在所有按钮上都是相同的。是否有一种自动调整大小的函数可以保持一致?
英文:
So i have an excel workbook with ~15 ActiveX Command Buttons that are selected to run macros. They are all the same height and width but i have a sub running continously to always set the height and width to consistent values. This was implemented as sometimes the buttons would start changing sizes when pressed.
Recently we have noticed that sometimes the font size will keep reducing in size also so i wanted to hardwire their font size into the macros.
I have tried using functions like CommandButton1.font.size = 15
. This has worked but when I apply it to each of the buttons that same font size ends up displaying vastly different per button? I thought it might be due to the buttons dimensions but this cant be the case since this is the same across the buttons. Is there some sort of auto size function that will keep it consistent?
答案1
得分: 1
Sub fonttype()
For i = 1 To ActiveSheet.OLEObjects.Count
With ActiveSheet.OLEObjects(i).Object
On Error Resume Next
.Font.Size = 15
End With
Next i
On Error Goto 0
End Sub
执行此操作后,所有对象都将具有相同的字体大小。
通过使用On Error语句,可以消除没有.Font.Size属性的对象。
英文:
Sub fonttype()
For i = 1 To ActiveSheet.OLEObjects.Count
With ActiveSheet.OLEObjects(i).Object
On Error Resume Next
.Font.Size = 15
End With
Next i
On Error Goto 0
End Sub
After this all objects will have the same font size.
With the On Error statement eliminate objects which hasn't property .Font.Size
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论