VBA-excel工作表操作
1. 工作表的隐藏
sub s1()
sheets(2).visible = Ture
end sub
2. 工作表的移动
sub s2()
sheets("sheet2").Move before:=shets("sheet1") 'sheet2移动到sheet1前
sheets("sheet1").Move after:=shets("sheet2") 'sheet1移动到sheet2后
end sub
3. 工作表的复制+另存为
sub s3()
Dim wb As workbook
Sheets("src").copy
set wb=activeworkbook
wb.saveas Thisworkbook.path & "tgt.xls"
wb.sheets(1).Range("a1") = "test"
wb.close ture
end sub
4. 工作表的复制
sub s3()
Dim sh As worksheet
Sheets("src").copy befoer := sheets(1)
set sh=activesheet
sh.name="test"
end sub
5. 保护工作表
sub s5()
sheets(1).protect "123456"
if sheet(1).protesctContents = Ture then
MSGBox "protected worksheet"
end if
end sub
6. Del工作表
sub s6()
Application.DisplayAlerts = False '屏蔽提示框
Sheets("test").delete
Application.DisplayAlerts = Ture
end sub
7. Sel工作表
sub s7()
Sheets(1).select
end sub