按照你的意思,
就不应该做在sheet上,
而应该使用ToolBar,
ToolBar是可以漂浮在窗口上的,
不随sheet变化而变化,
甚至删除sheet都没有问题。
Sub My_Bar_Set()
Dim myBar As CommandBar
Dim myBtm As CommandBarButton
'建立新"Bar1"工具栏
Set myBar = CommandBars.Add("bar1", msoBarFloating)
Set myBtm = CommandBars("Bar1").Controls.Add(Type:=msoControlButton)
'设置"Bar1"工具栏
With Application.CommandBars("Bar1").Controls(1)
.OnAction = "My_menu" 'My_menu是一个sub,里面是单击按钮后要执行的程序
.Caption = "asd"
.Height = 12
.Width = 51
.Visible = True
.Enabled = True
End With
'根据显示器分辨率设置"Bar1"位置
Dim H As Long
Dim V As Long
H = 800 '我的显示器设为800*600,你可以根据你的分辨率填写
V = 600
With Application.CommandBars("Bar1")
.Top = V / 2
.Left = H - 80
.Visible = True
End With
End Sub
Sub My_menu()
ActiveCell.Value = 1234 '此处为随意写了一句,这段程序是设置在工作簿open时自动运行的,原程序是调用一个窗口,然后进行选择操作
End Sub