forked from AllenMattson/VBA_personal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddOptionPrivateModule.vb
36 lines (27 loc) · 1.1 KB
/
AddOptionPrivateModule.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Option Explicit
Option Private Module
'---------------------------------------------------------------------------------------
' Method : AddOptionPrivate
' Author : stackoverflow.com
' Date : 12.01.2017
' Purpose: Checking for "Option Private Mod~" up to line 5, if not found we add it in
' every module
'---------------------------------------------------------------------------------------
Sub AddOptionPrivate()
Const UP_TO_LINE = 5
Const PRIVATE_MODULE = "Option Private Module"
Dim objXL As Object
Dim objPro As Object
Dim objComp As Variant
Dim strText As String
Set objXL = GetObject(, "Excel.Application")
Set objPro = objXL.ActiveWorkbook.VBProject
For Each objComp In objPro.VBComponents
If objComp.Type = 1 Then
strText = objComp.CodeModule.Lines(1, UP_TO_LINE)
If InStr(1, strText, PRIVATE_MODULE) = 0 Then
objComp.CodeModule.InsertLines 2, PRIVATE_MODULE
End If
End If
Next objComp
End Sub