Excellearning
XLDnaute Nouveau
Bonjour chers membres;
Je sollicite votre aide sur un souci que je rencontre sur le code suivant:
Public Function SheetExist(Sheetname As String) As Boolean
'Workbooks(AppName).Unprotect (PasswordWk)
Dim ws As Worksheet
SheetExist = False
For Each ws In Workbooks(AppName).Sheets
If ws.Name = Sheetname Then
SheetExist = True: 'Workbooks(AppName).Protect (PasswordWk): Exit Function
End If
Next
'Workbooks(AppName).Protect (PasswordWk)
End Function
Public Function CreateSheet(Sheetname As String) As Boolean
'On Error Resume Next
Dim Count As Long
Dim ws As Worksheet
Dim wb As Workbook
If SheetExist(Sheetname) Then
CreateSheet = True
Exit Function
Else
Workbooks(AppName).Unprotect (PasswordWk)
Count = Workbooks(AppName).Sheets.Count
Set wb = Workbooks(AppName)
Set ws = wb.Sheets.Add(after:=wb.Sheets(Count))
'Workbooks(AppName).Unprotect (PasswordWk)
ws.Name = Sheetname
'Workbooks(AppName).Unprotect (PasswordWk)
ws.Visible = xlSheetHidden
CreateSheet = True
Workbooks(AppName).Protect (PasswordWk)
End If
End Function
Ci-joint la capture des erreurs.
Je sollicite votre aide sur un souci que je rencontre sur le code suivant:
Public Function SheetExist(Sheetname As String) As Boolean
'Workbooks(AppName).Unprotect (PasswordWk)
Dim ws As Worksheet
SheetExist = False
For Each ws In Workbooks(AppName).Sheets
If ws.Name = Sheetname Then
SheetExist = True: 'Workbooks(AppName).Protect (PasswordWk): Exit Function
End If
Next
'Workbooks(AppName).Protect (PasswordWk)
End Function
Public Function CreateSheet(Sheetname As String) As Boolean
'On Error Resume Next
Dim Count As Long
Dim ws As Worksheet
Dim wb As Workbook
If SheetExist(Sheetname) Then
CreateSheet = True
Exit Function
Else
Workbooks(AppName).Unprotect (PasswordWk)
Count = Workbooks(AppName).Sheets.Count
Set wb = Workbooks(AppName)
Set ws = wb.Sheets.Add(after:=wb.Sheets(Count))
'Workbooks(AppName).Unprotect (PasswordWk)
ws.Name = Sheetname
'Workbooks(AppName).Unprotect (PasswordWk)
ws.Visible = xlSheetHidden
CreateSheet = True
Workbooks(AppName).Protect (PasswordWk)
End If
End Function
Ci-joint la capture des erreurs.