Funcția de mai jos verifică dacă un registru de lucru (workbook) conține foi de lucru (sheets) nefolosite (goale).
1. Option Explicit
2.
3. Function FoiGoaleInWorkbook(ByRef TestareWorkbook As Workbook) As Boolean
4. Dim objWorksheet As Worksheet
5. FoiGoaleInWorkbook = False
6. For Each objWorksheet In TestareWorkbook.Worksheets
7. If Application.WorksheetFunction.CountBlank _
(objWorksheet.Range("A1:IV65536")) = 16777216 Then
8. FoiGoaleInWorkbook = True
9. Exit Function
10. End If
11. Next objWorksheet
12. End Function
13.
14. Sub Verific_Foi_Goale_In_Workbook()
15. If FoiGoaleInWorkbook(ActiveWorkbook) = True Then
16. MsgBox "Acest registru contine una sau mai multe foi de lucru goale." & _
vbCr & vbCr & "Va rugam sa le stergeti inainte de a" & _
" inchide registrul.", vbOKOnly & vbExclamation, _
"Verificare daca exista foi de lucru goale. "
17. End If
18. End Sub
Iată cum funcționează codul: