简体   繁体   English

Workbook_Open事件的其他问题

[英]Different issues with the Workbook_Open event

After some research on the internet and on Stackoverflow, I'm stuck on some elements about the functionning of the event : Workbook_Open (which will surely seems simple to you). 在互联网和Stackoverflow上进行了一些研究之后,我停留在有关事件功能的一些要素上:Workbook_Open(对您来说这似乎很简单)。
I wrote the following code : 我写了以下代码:

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

Precisions: 精度:
CB1 is the name of a button implanted on an excel sheet called "Search" CB1是在Excel工作表上植入的名为“搜索”的按钮的名称。

I have two different problems : 我有两个不同的问题:

Problem n°1 : 问题n°1:
Excel doesn't seem to recongnize the CB1 variable outside of a code written on the "Search" sheet. Excel似乎没有在“搜索”表上编写的代码之外重新识别CB1变量。 I don't understand why. 我不明白为什么。 Is the variable CB1 not supposed to be available for all the code of the Workbook ? 变量CB1是否不应该对工作簿的所有代码都可用?

Problem n°2 问题n°2
I simply do not see why Line 2 doesn't work. 我根本不明白为什么2号线不起作用。 Even when I write it in another procedure that I call afterwards. 即使当我在随后调用的另一个过程中编写它时,也是如此。

Anyone can give me a suggestions ? 有人可以给我建议吗?
Best regards and thanks ! 最好的问候和感谢!

Your code should look something like this: 您的代码应如下所示:

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

Please see the following link for maximum row height in Excel: https://support.office.com/en-ie/article/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3 请在Excel中查看以下链接以获取最大行高: https : //support.office.com/zh-cn/article/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM