Excel VBA怎么判断 一个sheet是否存在 如果不存在则创建他
3个回答
展开全部
Sub run()
On Error GoTo 999
Sheets("sheet1").Select
Exit Sub
999
Sheets.Add
ActiveSheet.Name = "sheet1"
End Sub
On Error GoTo 999
Sheets("sheet1").Select
Exit Sub
999
Sheets.Add
ActiveSheet.Name = "sheet1"
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
On Error Resume Next
MkDir "D:\xxx" ' 不存在就建一个,已存在则跳到下一句
MkDir "D:\xxx" ' 不存在就建一个,已存在则跳到下一句
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
function CheckSheet(sName as string) as boolean
dim ws as worksheet
on error goto TT
set ws=thisworkbook.worksheets(sName)
checksheet=ture 'worksheet exists
exit function
TT:
checksheet=false 'no sheet found
end function
function AddSheet()
dim ws as worksheet,sKey as string
skey="kk"
if checksheet(skey)=false then
set ws=thisworkbook.worksheet.add
ws.name=skey
end if
end function
dim ws as worksheet
on error goto TT
set ws=thisworkbook.worksheets(sName)
checksheet=ture 'worksheet exists
exit function
TT:
checksheet=false 'no sheet found
end function
function AddSheet()
dim ws as worksheet,sKey as string
skey="kk"
if checksheet(skey)=false then
set ws=thisworkbook.worksheet.add
ws.name=skey
end if
end function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询