如何在Excel 里用VBA代码为多个工作表中增加一个返回主页按键? 10
2个回答
展开全部
Public sub addButton()
Dim i As Integer
Dim n As Integer
Dim SheetName as String
n = ActiveWorkbook.Sheets.Count
For i = 1 To n
SheetName =ActiveWorkbook.Sheets(i).Name
if SheetName <> "主页界面" then
Call Worksheets(SheetName ).OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False , DisplayAsIcon:=False, Left:=108.75, Top:=1.5, Width:=110.25, Height _
:=40.5)
end if
Next
End sub
然后在每一页里面加上以下语句
Private Sub CommandButton1_Click()
Worksheets("主页界面").Activate
End Sub
Dim i As Integer
Dim n As Integer
Dim SheetName as String
n = ActiveWorkbook.Sheets.Count
For i = 1 To n
SheetName =ActiveWorkbook.Sheets(i).Name
if SheetName <> "主页界面" then
Call Worksheets(SheetName ).OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False , DisplayAsIcon:=False, Left:=108.75, Top:=1.5, Width:=110.25, Height _
:=40.5)
end if
Next
End sub
然后在每一页里面加上以下语句
Private Sub CommandButton1_Click()
Worksheets("主页界面").Activate
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询