关于论坛问题的问题_“Excel命令按钮标题文本缩小到太小而无法阅读” [英] Question regarding the Forum question_"Excel Command Button Caption text shrinks till too small to read"

查看:84
本文介绍了关于论坛问题的问题_“Excel命令按钮标题文本缩小到太小而无法阅读”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的按钮大小也有问题我解决了这个问题:

 

Sub LoadButtonSizeTB()

表格("技术背景")。选择

ActiveSheet.Shapes.Range(Array(" ReferencesTB"))。选择

ActiveSheet.Shapes(" Refe rencesTB")。宽度= 100

ActiveSheet.Shapes(" ReferencesTB")。高度= 42

End Sub

这很好用,但随后字体大小也开始变化。所以我尝试了:

< span lang ="EN-US"style ="font-size:10.0pt; font-family:'Arial','sans-serif'"> Sub LoadButtonSizeTB()

表格("技术背景")。选择

< span lang ="EN-US"style ="font-size:10.0pt; font-family:'Arial','sans-serif'"> ActiveSheet.Shapes.Range(Array(" ReferencesTB"))。选择

ActiveSheet.Shapes(" ReferencesTB")。Width = 100

ActiveSheet.Shapes(" ReferencesTB")。高度= 42

使用Selection.Font

With Selection.Font

    .Size = 8

    .Size = 8

    End With

    End With

End Sub

以及

Sub LoadButtonSizeTB()

表格("技术背景")。选择

< span lang ="EN-US"style ="font-size:10.0pt; font-family:'Arial','sans-serif'"> ActiveSheet.Shapes.Range(Array(" ReferencesTB"))。选择

ActiveSheet.Shapes(" ReferencesTB")。Width = 100

ActiveSheet.Shapes(" ReferencesTB")。Height = 42

使用Selection.Characters(开头:= 1,长度:= 17).Font

With Selection.Characters(Start:=1, Length:=17).Font

。尺寸= 12

.Size = 12

结尾

End With

End Sub

对于两次尝试,我只得到运行时错误#438':对象不支持此属性或方法。

 

按钮出现问题,我从一张纸切换到另一张(可能是因为不同纸张的缩放不一样?)

它也会出现如果我点击按钮,但对于这种情况,zandvan的程序完美无缺。

但我不知道如何应用它,如果我只在同一工作簿中从工作表切换到另一个,我没有Click事件。如何告诉VBA,采取哪个按钮?

非常感谢您的帮助!

亲切的问候,Christina

推荐答案

Shape si zes应设置为100%缩放,然后根据需要设置缩放。我通常设置形状(按钮)相对于列和行位置以及列宽和行高的位置和大小。

Shape sizes should be set with Zoom at 100% and then set zoom as required. I usually set the position and size of the shape (button) relative to the column and row positions and column widths and row heights.

如果将以下代码放在工作表模块中,那么它每次激活工作表时都会自动运行。代码读取当前缩放设置,将缩放设置为100%,调整按钮大小并将缩放重置为先前的设置。

If you place the following code in the worksheets module then it will run automatically each time the worksheet is activated. The code reads the current zoom setting, sets zoom to 100%, resizes the button and resets the zoom to the previous setting.

要安装代码,请右键单击工作表选项卡名称并选择查看代码以在正确的模块中打开VBA编辑器。

To install the code, right click the worksheet tab name and select View code to open the VBA editor at the correct module.

将代码复制到模块中。 (不要更改子名称,否则激活工作表时不会运行。)

Copy the code into the module. (do not change the sub name or it will not run when the sheet is activated.)

如果您有多张纸上的按钮,则将代码复制到属于每张纸的模块中并编辑按钮名称是必需的。

If you have buttons on several sheets then copy the code into the module belonging to each sheet and edit the button name as required.

请注意,Me是代码模块所属工作表的通用引用。

Note that Me is the generic reference for the worksheet to which the code module belongs.

我添加了一些额外的字体和颜色的代码但你可以编辑代码到你想要的按钮特征(包括你的标题中的字符数)

I have added some extra code for the font and color but you can edit the code to your desired characteristics for the button (including the number of characters in your caption)

AFAIK窗体控制按钮的背景颜色不能要更改。

AFAIK the background color of a forms control button cannot be changed.

要为按钮指定所需的宏,请右键单击按钮并选择指定宏并按照提示进行操作。

To assign a required macro to the button, right click the button and select Assign macro and follow the prompts.

您可以指定相同的宏到不同的按钮,并使用应用程序调用程序和活动表命令来确定单击了哪个按钮。 (请参阅按钮调整大小和位置代码后的示例。)

You can assign the same macro to different buttons and use the Application caller and activesheet commands to determine which button was clicked. (See example after the button resize and position code).

如果出现任何问题,请随时回复我,但在我回答之前会有8到10个小时左右,因为它是几乎在我这个地方的睡觉时间。

Feel free to get back to me if any problems but it will be another 8 - 10 hours or so before I answer because it is almost bed time in my part of the world.

Private Sub Worksheet_Activate()

Private Sub Worksheet_Activate()

  &NBSP;&NBSP; Dim shp As Shape

    Dim dblZoom As Double

    Dim n As Long

   

    dblZoom = ActiveWindow.Zoom  '保存用户的缩放设置

   

    ActiveWindow.Zoom = 100     '设置缩放100%

   

   设置shp = Me.Shapes(" ReferencesTB")

   

   使用shp

       

        .Top = Me.Rows(3).Top

        .Left = Me.Columns(" D")。Left

        .Width = Me.Columns("D:G")。宽度

        .Height = Me.Rows(" 3:5"。)。高度为
        .Placement = xlMoveAndSize  '允许移动和调整单元格大小

         n = Len(.TextFrame.Characters.Text)    '字幕中的字符数

        .TextFrame.Characters(1,n).Font.Size = 16      'n用于字符数

        .TextFrame.Characters(1,n).Font.Color = vbRed

        .TextFrame.Characters(1,n).Font.Bold = True

   结束与$
   

    ActiveWindow.Zoom = dblZoom     '返回用户之前的缩放

    Dim shp As Shape
    Dim dblZoom As Double
    Dim n As Long
   
    dblZoom = ActiveWindow.Zoom  'Save the user's zoom setting
   
    ActiveWindow.Zoom = 100     'Set zoom 100%
   
    Set shp = Me.Shapes("ReferencesTB")
   
    With shp
       
        .Top = Me.Rows(3).Top
        .Left = Me.Columns("D").Left
        .Width = Me.Columns("D:G").Width
        .Height = Me.Rows("3:5").Height
        .Placement = xlMoveAndSize  'allow to move and size with cells
         n = Len(.TextFrame.Characters.Text)    'Number of characters in the caption
        .TextFrame.Characters(1, n).Font.Size = 16      'n is used for number of characters
        .TextFrame.Characters(1, n).Font.Color = vbRed
        .TextFrame.Characters(1, n).Font.Bold = True
    End With
   
    ActiveWindow.Zoom = dblZoom     'Return to users previous zoom

结束子

以下是确定调用哪个按钮的示例一个子。以下代码在标准模块中。不要将它放在工作表模块中,因为它不能从那里运行。

Following is an example of determining which button called a sub. The following code goes in a standard module. DO NOT put it in the worksheets module with the worksheet activate code because it will not run from there.

Sub CalledFromButton()

    Dim ws As Worksheet

    Dim strButtonName As String

   

   设置ws = ActiveSheet        '将是按钮所在的纸张

   

    strButtonName = Application.Caller

   

    MsgBox strButtonName

End Sub

Sub CalledFromButton()
    Dim ws As Worksheet
    Dim strButtonName As String
   
    Set ws = ActiveSheet        'Will be the sheet that the button is on
   
    strButtonName = Application.Caller
   
    MsgBox strButtonName
End Sub


这篇关于关于论坛问题的问题_“Excel命令按钮标题文本缩小到太小而无法阅读”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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