VBA创建⼀个“录⼊窗体”⼯具栏Private Sub Workbook_Activate()vba做excel窗体录入教程
On Error Resume Next
Application.CommandBars("我的⼯具栏").Delete
Dim ⼦菜单 As CommandBarControl
For m = 1 To 2
Select Case m
Case 1
Set 主菜单 = Application.CommandBars.Add
With 主菜单
.Visible = True
.Name = "我的⼯具栏"
.
Position = msoBarTop------------改成msoBarLeft 0 命令栏固定在应⽤程序窗⼝的左侧。
End With
Case 2
Set 主菜单 = Application.CommandBars("Cell").Controls.Add(Type:=msoControlPopup, before:=1)
主菜单.Caption = "⼯具栏"
End Select
For i = 1 To 1
Set ⼦菜单 = 主菜单.Controls.Add(Type:=msoControlButton)
With ⼦菜单
.Caption = Array("录⼊窗体")(i - 1)
.Style = msoButtonIconAndCaptionBelow
.
OnAction = Array("录⼊窗体")(i - 1)
.FaceId = 284
.BeginGroup = True
End With
Next
Next
End Sub
Private Sub Workbook_Deactivate()
On Error Resume Next
Application.CommandBars("我的⼯具栏").Delete
Application.CommandBars("Cell").Controls("⼯具栏").Delete
End Sub
---------------------
这句代码放在模块内:
Public Sub 录⼊窗体()
UserForm1.Show
End Sub
Sub EnaBar()
Dim myBar As CommandBar
Debug.Print CommandBars.Count
For Each myBar In CommandBars
Debug.Print myBar.Name
If myBar.Type = msoBarTypePopup Then
myBar.Enabled = True
End If
Next
End Sub