Good day All
Code below handle only procedure, how to use it replace Enum string "Level" "LVL" ?
THX.
Code below handle only procedure, how to use it replace Enum string "Level" "LVL" ?
THX.
Code:
Option Explicit
[COLOR=#b22222]Public Enum SecurityLevelp[/COLOR]
IllegalEntry = 0
Security[COLOR=#0000ff][B]Level[/B]1[/COLOR] = 1
Security[B][COLOR=#0000ff]Level[/COLOR][/B]2 = 8
Security[B][COLOR=#0000ff]Level[/COLOR][/B]3
Security[COLOR=#0000ff]Level[/COLOR]4 = 10
[COLOR=#b22222]End Enum[/COLOR]
[B][COLOR=#006400]Public Sub SecurityLevel()[/COLOR][/B]
Cells.Clear
[A1] = "Security[B][COLOR=#0000ff]Level[/COLOR][/B]"
[A2] = "Security[B][COLOR=#0000ff]Level[/COLOR][/B]2" 'Level
[B][COLOR=#008000]End Sub 'Level[/COLOR][/B]
[COLOR=#ff0000][B]Public Sub Test1()[/B][/COLOR]
AddRef ThisWorkbook, "{0002E157-0000-0000-C000-000000000046}", "VBIDE", 5, 3
Call VBRplcr("SecurityLevelp", [COLOR=#0000ff]"[B]LVL[/B][/COLOR]", "[B][COLOR=#0000ff]Level[/COLOR][/B]") 'to replace enum
Call VBRplcr("SecurityLevel", "[COLOR=#0000ff][B]LVL[/B][/COLOR]", "[B][COLOR=#0000ff]Level[/COLOR][/B]")
[B][COLOR=#ff0000]End Sub[/COLOR][/B]
[B][COLOR=#ff0000]Public Sub Test2()[/COLOR][/B]
AddRef ThisWorkbook, "{0002E157-0000-0000-C000-000000000046}", "VBIDE", 5, 3
Call VBRplcr("SecurityLevelp", "[B][COLOR=#0000ff]Level[/COLOR][/B]", "[B][COLOR=#0000ff]LVL[/COLOR][/B]") 'to replace enum
Call VBRplcr("SecurityLevel", "[COLOR=#0000ff][B]Level[/B][/COLOR]", "[COLOR=#0000ff][B]LVL[/B][/COLOR]")
[B][COLOR=#ff0000]End Sub[/COLOR][/B]
Sub VBRplcr(PrcName As String, Fnd As String, Rplc As String)
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
Dim ProcStrLn As Long, ProcAcStrLn As Long, ProcCntLn As Long, N As Long, PrcCnountLine As Long
Set VBProj = ThisWorkbook.VBProject
For Each VBComp In VBProj.VBComponents
With VBComp
If .Type = vbext_ct_StdModule Then ' Withen Standr Module
With .CodeModule
If InStr(1, .Lines(1, .CountOfLines), PrcName) > 0 Then
On Error Resume Next
ProcStrLn = .ProcStartLine(PrcName, vbext_pk_Proc) ' Procedure Start Line
ProcAcStrLn = .ProcBodyLine(PrcName, vbext_pk_Proc) ' Actually Procedure Start Line
ProcCntLn = .ProcCountLines(PrcName, vbext_pk_Proc)
PrcCnountLine = ProcCntLn - (ProcAcStrLn - ProcStrLn)
If PrcName = .ProcOfLine(ProcAcStrLn, vbext_pk_Proc) Then 'Get Proce Name
For N = (ProcAcStrLn + 1) To (ProcAcStrLn + PrcCnountLine - 1) ' Add 1 to avoid chane Procedure Name and -1 to avoid replace Next Procedure
MsgBox .Lines(N, 1)
If InStr(N, .Lines(N, 1), Fnd, vbTextCompare) > 0 Then
.ReplaceLine N, Replace(.Lines(N, 1), Fnd, Rplc, 1, , vbTextCompare) 'replace
End If
Next
End If
On Error GoTo 0
End If
End With ' .CodeModule
End If ' .Type
End With ' VBComp
Next ' In VBProj.VBComponents
End Sub
Sub AddReferenceVBA()
AddRef ThisWorkbook, "{0002E157-0000-0000-C000-000000000046}", "VBIDE", 5, 3
End Sub
Sub AddRef(wbk As Workbook, sGuid As String, sRefName As String, sRefMajor As Long, sRefMinor As Long)
Dim i As Integer
On Error GoTo EH
With wbk.VBProject.References
For i = 1 To .Count
If .Item(i).Name = sRefName Then
Exit For
End If
Next i
If i > .Count Then
.AddFromGuid sGuid, sRefMajor, sRefMinor ' 0,0 should pick the latest version installed on the computer
End If
End With
EX: Exit Sub
EH: MsgBox "Error in 'AddRef'" & vbCrLf & vbCrLf & Err.Description
Resume EX
Resume ' debug code
ThisWorkbook.Save
End Sub
Last edited: