gpt4 book ai didi

vba - 通过打开工作表启动 VBA 宏

转载 作者:行者123 更新时间:2023-12-04 20:41:40 25 4
gpt4 key购买 nike

如何通过打开 Excelsheet 来启动宏。我已经放了这段代码:

Public Sub Workbook_Open()

Application.ScreenUpdating = False

With Tabelle1.ListBox1

.AddItem "TEST1"
.AddItem "TEST2"
.AddItem "TEST3"
End With

With Tabelle1.ListBox2

.AddItem "TEST4"
.AddItem "TEST5"
End With

With Tabelle1.ListBox1
.Width = 140.25
.Height = 255.25

End With
With Tabelle1.ListBox2
.Width = 78
.Height = 69.75
End With

Call EnterInDesignMode
Call ExitInDesignMode
Application.ScreenUpdating = True
End Sub

进入 Private Sub Workbook_Open() .但它没有进入第二个代码。
我在这里做错了什么?

两个代码都高于 Public Sub Workbook_Open()
'first Code
Sub EnterInDesignMode()
With Application.CommandBars.FindControl(ID:=1605)
.Execute
End With
End Sub

'Second Code
Sub ExitInDesignMode()
Dim sTemp As String
With Application.CommandBars("Exit Design Mode")
sTemp = .Controls(1).Caption
End With
End Sub

两个代码都在工作,但它不会停止调用 EnterInDesignMode() ,所以它不会调用 ExitInDesignMode() .

最佳答案

With CommandBars("Exit Design Mode").Controls(1)
If .State = msoButtonDown Then .Execute
End With

编辑您对此拥有的代码,如我评论的链接中发布的那样。

来源: https://groups.google.com/forum/#!topic/microsoft.public.excel.programming/XN27a-Gxz6g

关于vba - 通过打开工作表启动 VBA 宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31672063/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com