你是要在Excel的菜单手袭缓上点击吗?
那样你的添加一个菜单:
Private Sub Workbook_Open()
Dim TargetBar As CommandBar
Dim NewMenu As Object
Dim NewItem As Object
Dim NewMenuTemp As Object
Set TargetBar = Application.CommandBars("Worksheet Menu Bar")
TargetBar.Visible = True
For Each NewMenuTemp In TargetBar.Controls
If NewMenuTemp.Caption = "Function" Then
Exit Sub
End If
Next
Set NewMenu = TargetBar.Controls.Add(Type:=msoControlPopup, ID:=1, Temporary:=True)
NewMenu.Caption = "Function"
Set NewItem = NewMenu.Controls.Add(Type:=msoControlButton, ID:=1, Temporary:=True)
NewItem.Caption = "毕模Function 1"
NewItem.OnAction = "模块1.function1"
Exit Sub
End Sub
以上代码禅告放到thisworkbook里,然后在模块1里添加function1
sub function1()
UserForm1.show
end sub
这样excel启动后会在excel的菜单上新增个菜单Function,点击里边的Function1就可以了。
UserForm1.show
xieyb0417老师的代码就非常好,完全达到你的要求