Access

Eliminar números de línea en VBA

VBA

Módulo estándar

'module: modRemoveLineNumbers_GG (Geoff Griffith)
'*************** Code Start ***********************************************
' Purpose  : remove the line numbers and replace with spaces
'              from all classes and modules within the current database file
' Author   : Geoff Griffith
' Code List: 
' This code: 
' LICENSE  :
'   You may freely use and share this code, but not sell it.
'   Keep attribution. Mark your changes. Use at your own risk.
'-------------------------------------------------------------------------------
'           RemoveLineNumbers_GG
'-------------------------------------------------------------------------------
Public Sub RemoveLineNumbers_GG() 
On Error GoTo HandleErrors 

 ' NOTE: This code requires a reference to:
    '       Microsoft Visual Basic for Applications Extensibility
    '       for early binding -- late binding recommended by Jack Stockton
    '
    Dim vbProj As Object  'VBIDE.VBProject
    Dim vbComp As Object  'VBIDE.VBComponent
    Dim modCurrent As Object  'VBIDE.CodeModule

    Dim iLine As Long 
    Dim sLineText As String 
    Dim sFirstWord As String 
    Dim sReplacement As String 
    Dim sNewText As String 
    
    Set vbProj = Application.VBE.VBProjects(1) 
    For Each vbComp In vbProj.VBComponents 
        
        Set modCurrent = vbComp.CodeModule 
        For iLine = 1 To modCurrent.CountOfLines 
            
            sLineText = Trim$(modCurrent.Lines(iLine,1)) 
            If Len(sLineText) > 0 Then 
                If InStr(1,sLineText, " ") > 0 Then 
                    sFirstWord = Trim$(Left$(sLineText,InStr(1,sLineText, " ") - 1)) 
                    If IsNumeric(sFirstWord) Then 
                        sReplacement = String(Len(sFirstWord), " ") 
                        sLineText = modCurrent.Lines(iLine,1) 
                        sNewText = Right$(sLineText,Len(sLineText) - (InStr(sLineText,sFirstWord) + Len(sFirstWord) - 1)) 
                        sNewText = Left$(sLineText,InStr(sLineText,sFirstWord) - 1) & sReplacement & sNewText 
                        modCurrent.ReplaceLine iLine,sNewText 
                    End If 
                End If 
            End If 
                
        Next iLine 
        
    Next 
    
    MsgBox  "Done removing line numbers",, "Done"
    
ExitMethod: 
    Exit Sub 
HandleErrors: 
    MsgBox  "Error: " & Err.Description,vbCritical, "Error " & Nz(Err.Number, "") 
    Resume ExitMethod 
End Sub 
'*************** Code End *****************************************************

El código se generó con colores utilizando el complemento gratuito Color Code para Access

Publicaciones relacionadas

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

Botón volver arriba