QUESTION: Private Sub Workbook_Open() Dim VBComp As VBIDE.VBComponent Dim LineCount As Long Dim N As Long Dim S As String Set VBProj = Application.Workbooks("Book1.xls").VBProject If VBProj.Protection = vbext_pp_locked Then
LineCount = -1
End If For Each VBComp In VBProj.VBComponents If VBComp.Collection.Parent.Protection = vbext_pp_locked Then
LineCount = -1
End If With VBComp.CodeModule
For N = 1 To .CountOfLines S = .Lines(N, 1) If Trim(S) = vbNullString Then ElseIf Left(Trim(S), 1) = "'" Then Else LineCount = LineCount + 1 End If Next N
End With Next VBComp Debug.Print LineCount End Sub
I hope that you help me to know why my antivirus program removes the above module from my VBproject is there a reason and kindly, how can I solve this problem to save this part of the module. Thanks very much in advance
ANSWER: Some antivirus programs are very strict on VBA code that accesses your VBA projects and obviously yours is too.
The best you can do is to prevent your viruss canner from scanning a specific folder and put your file there.
NB: Why are you counting the non-empty code lines in the VBA project of a fixed file named Book1.xls?
---------- FOLLOW-UP ----------
QUESTION: I am very thankful for your very fast and clear answer. Regarding your NB I use that for the following: 1- My project was too long and I used the code lines to measure how much I improved it. 2- I used the code lines to discover any changes happened by mistake and where were these changes. 3-I have an idea to use the code lines as an internal code security if any changes done in the project by anybody else the code will protect some of the company sensitive information. Do you advise me to continue with the third point or it will be enough to use the normal passwords? The true name of the file is "Company Costs.xls".
1 and 2: here is a free utility that has a code statistics option built-in and lots of other tools for the VBA programmer (MZ-Tools): http://www.mztools.com/v3/mztools3.aspx
3: To be able to detect if your code has been tampered with, sign the code with a digital signature: http://msdn.microsoft.com/en-us/library/aa141471(office.10).aspx
The signature will be removed if someone saves your file after modifying the VBA project in any way.
Advertisement