如何通过打开Excel表格来启动宏。我已经把这段代码写了:
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()
。
答案 0 :(得分:1)
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