Hello to all of the forum,

I am wirting this post as I do not know how to define a vba code in Excel.
I am using Excel2003.

I have a file which is limited of using.
After 10 times using it, a Msgbox is opened, informing that the file will close and cannto be used anymore.

I added following code in ThisWorbook:

Option Explicit
' Limiter le nombre d'utilisation d'un classeur

Private Sub Workbook_Open()
On Error Resume Next
If ActiveWindow.Visible = False Then ' Active Sheet not visible
Application.Quit ' close Excel
Exit Sub
On Error Resume Next
ElseIf Worksheets("Feuil2").Range("A6").Value >= 2 Then
ActiveWindow.Visible = False
Application.Quit
Exit Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
With Worksheets("Feuil2").Range("A2").Value = Worksheets("Feuil2").Range("A2").Value + 1
End With
ActiveWorkbook.Save
Application.Quit
End If
End Sub


So far the vba code is functionning.

As the files was opened 10 times, it is closing.
When clicking o nthe file in the registry it is opening and closing immediatelay.

I would like to ask how to define, which vba code is needed,
that when the file is closing, that the file cannot be used anymore, cannot be opened at all. Means if clicking on it, gets shown a sing 'error'. The file is not opening.

Thanks in advance for some information,