在互联网和Stackoverflow上进行了一些研究之后,我停留在有关事件功能的一些要素上:Workbook_Open(对您来说这似乎很简单)。
我写了以下代码:
Public Sub Workbook_Open()
' Désactivation des évènements
Application.EnableEvents = False
' Put the back color of a button to red
' line 1
CB1.BackColor = &HC0&
' Modify the RowHeight of a line
' line 2
ThisWorkbook.Worksheets("Search").Rows("12:12").RowHeight = 800
' Réactive l'évènement
Application.EnableEvents = True
End Sub
注意事项:
CB1是植入到Excel工作表中名为“搜索”的按钮的名称
我有两个不同的问题:
问题1:
Excel似乎没有在“搜索”表上编写的代码之外重新识别CB1变量。我不明白为什么。变量CB1是否不应该对工作簿的所有代码都可用?
问题n°2
我根本不明白为什么2号线不起作用。
甚至当我在随后调用的另一个过程中编写它时。
任何人都可以给我一个建议吗?
最好的问候和感谢!
答案 0 :(得分:1)
您的代码应如下所示:
Public Sub Workbook_Open()
' Désactivation des évènements
Application.EnableEvents = False
' Put the back color of a button to red
' line 1
'sheet specification a requirement
Sheets("Search").CB1.BackColor = &HC0&
' Modify the RowHeight of a line
' line 2
' maximum row height is 409
Sheets("Search").Rows(12).RowHeight = 409
' Réactive l'évènement
Application.EnableEvents = True
End Sub
有关Excel中最大行高,请参见以下链接:https://support.office.com/en-ie/article/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3