Views

Histats

Vitrine

VBA Excel - Deletando uma procedure de um módulo - Delete a procedure from a module

Inline image 1

Esse código permite que você apague somente uma procedure dentro de um módulo. Alteração cirúrgica!

DeleteProcedureCode Workbooks ("wb_Bernardes.xlsb"), "mdl_Functions", "ExtractData"

Sub DeleteProcedureCode (ByVal wb As Workbook, _
                                           ByVal DeleteFromModuleName As String, _
                                           ByVal ProcedureName As String)

' deletes ProcedureName from DeleteFromModuleName in wb
Dim VBCM As CodeModule, ProcStartLine As Long, ProcLineCount As Long

On Error Resume Next

    Set VBCM = wb.VBProject.VBComponents(DeleteFromModuleName).CodeModule

    If Not VBCM Is Nothing Then
        ' determine if the procedure exist in the codemodule
        Let ProcStartLine = 0
        Let ProcStartLine = VBCM.ProcStartLine(ProcedureName, vbext_pk_Proc)

        If ProcStartLine > 0 Then ' prosedyren finnes, slett den
            Let ProcLineCount = VBCM.ProcCountLines(ProcedureName, vbext_pk_Proc)

            VBCM.DeleteLines ProcStartLine, ProcLineCount
        End If

        Set VBCM = Nothing
    End If

    On Error GoTo 0
End Sub

Reference:
Tags: VBA, Excel, content, module, módulo, Class Modules in VBA, delete, del, excluir, apagar, procedure, function 

LinkWithinBrazilVBAExcelSpecialist

Related Posts Plugin for WordPress, Blogger...