close

2058

Excel VBA 如何檢查工作表(名稱)是否存在

實用性

●○○

難易度

●○○○

範本檔

2058.XLSX

這個問題很感謝PCW這位專家的解答,內容如下:

Sub check_sht_names()

dim shtNames as string, shtArray as variant

dim sht as worksheet, pos as variant

' get all names of worksheets

for each sht in worksheets

shtNames = shtNames & "/" & sht.name

next sht

shtNames = Mid(shtNames, 2)

' make a list of worksheet names

shtArray = Split(shtNames, "/")

Rcnt = Worksheets("AA").Range("G6").End(xlDown).Row

For i = 7 To Rcnt

ShtN = Worksheets("AA").Range("G" & i).Value

pos = Application.Match(ShtN, shtArray, 0)

If IsError(pos) Then

With orksheets.Add(after:=worksheets(worksheets.count))

.Name = ShtN

End With

end if

Next i

End Sub

 


arrow
arrow
    創作者介紹

    錦子老師 發表在 痞客邦 留言(0) 人氣()