martedì 31 gennaio 2012

EXCEL VBA: VERIFICARE SE ESISTE UN FOGLIO DI LAVORO

La seguente funzione se inserita in un modulo VBA di excell consente di verificare l'esistenza di un foglio di lavoro (sheet) in un file excel (workbook):

Public Function SheetExists(sname) As Boolean
    ' Returns TRUE if sheet exists in the active workbook
    Dim x As Object
    On Error Resume Next
    Set x = ActiveWorkbook.Sheets(sname)
    If Err = 0 Then SheetExists = True _
    Else SheetExists = False
End Function

Nessun commento:

Posta un commento