Logo_Access_global_380x114Favicon_Access_global_180x180Logo_Access_global_380x114Logo_Access_global_380x114
  • Home
  • University
    • Destellos formativos
  • Labs
  • TV
  • Secciones
    • El mundo de Access
    • Explorando VBA
      • Artículos sobre VBA
      • Un trocito de código
    • Entrevistas
      • Profesionales de Access
    • El rincón de Excel
    • Bases de datos
      • MS SQL
      • MySQL
      • postgreSQL
      • SQLite
    • Clases magistrales
    • Utilidades hechas con Access
  • Access en el mundo
  • ¿Quiénes somos?
  • Cómo colaborar
  • Eventos
✕
            No hay resultados Mostrar todos los resultados
            VBA: métodos CreateReport y CreateForm
            06/06/2023
            VBA: captura de firma
            08/06/2023
            Mostrar todos

            VBA: extraer email de una cadena de texto

            Publicado por Luis Viadel
            Categorías
            • Destellos formativos
            Etiquetas
            • Execute
            • Mid
            • Pattern
            • VBScript.RegExp
            Public Function ExtractEmailAddress(strData As String, _
                Optional strDelim As String = ",") As String
            '-----------------------------------------------------------------------------------------------------------------------------------------------
            ' Fuente            : https://access-global.net/vba-extraer-email-de-una-cadena-de-texto/
            '                     Destello formativo 336
            '-----------------------------------------------------------------------------------------------------------------------------------------------
            ' Título            : ExtractEmailAddress
            ' Autor original    : thedbguy | http://www.accessmvp.com/thedbguy
            ' Creado            : junio 2015
            ' Propósito         : extraer una dirección de mail de una cadena de texto
            ' Argumento         : la sintaxis de la función consta de los siguientes argumentos:
            '                     Parte             Modo           Descripción
            '-----------------------------------------------------------------------------------------------------------------------------------------------
            '                     strData        Obligatorio      cadena de texto que contiene el email
            '                     strDelim        Opcional        delimitador de cada bloque de texto en la cadena
            '-----------------------------------------------------------------------------------------------------------------------------------------------
            ' Referencias       : https://www.regular-expressions.info/email.html
            '                     https://www.robvanderwoude.com/vbstech_regexp.php
            '                     https://learn.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-reference
            '-----------------------------------------------------------------------------------------------------------------------------------------------
            ' Test:             : Para adaptar este código en tu aplicación puedes basarte en este procedimiento test. Copiar el bloque siguiente al
            '                     portapapeles y pega en el editor de VBA. Descomentar la línea que nos interese y pulsar F5 para ver su funcionamiento.
            '
            'Private Sub btnQRTest_Click()
            'Dim resultado As String
            '
            '    resultado = ExtraeEmail("Pedro Martínez, C/calle de pedro 23, 2, 46015 Valencia, pedro@webdepedro.com, 666 666 666")
            '
            ' End Sub
            '-----------------------------------------------------------------------------------------------------------------------------------------------
            Dim regEx As Object
            Dim regExMatch As Object
            Dim var As Variant
            Dim strEmail As String
            
                Set regEx = CreateObject("VBScript.RegExp")
                
                    With regEx
            'Three properties are available for the RegExp object:
            'Global: if TRUE, find all matches, if FALSE find only the first match
                        .Global = True
            'IgnoreCase: if TRUE perform a case-insensitive search, if FALSE perform a case-sensitive search
                        .IgnoreCase = True
            'Pattern: the RegExp pattern to search for
                        .Pattern = "b[0-9A-Z._%+-]+@[0-9A-Z.-]+.[A-Z]{2,3}b"
            'Execute method: returns an object with the following properties:
            ' Count: the number of matches found in teststring (maximum is 1 if .Global = False)
            ' Item: the matches themselves as objects, each with the following properties:
            '       FirstIndex: the location of the matching substring in teststring
            '       Length    : the length of the matching substring
            '       SubMatches: if parentheses were used in the pattern: the matching pieces of the pattern between sets of parentheses as objects, each with the following properties:
            '                   Count: the number of submatches found in the match
            '                   Item : the string value of the submatch
            '                   value: the string value of the match
            'Another methods: test, replace
                        Set regExMatch = .Execute(strData)
                            For Each var In regExMatch
                                strEmail = strEmail & strDelim & var
                            Next
                        Set regExMatch = Nothing
                   End With
                    
                    ExtractEmailAddress = Mid(strEmail, Len(strDelim) + 1)
                
                Set regEx = Nothing
            
            End Function
            
            ¡Ver en el repositorio!
            Compartir
            15
            Luis Viadel
            Luis Viadel

            Entradas relacionadas

            27/09/2023

            VBA: Conversor de moneda


            Leer más
            26/09/2023

            VBA: Convertir macros a VBA


            Leer más
            25/09/2023

            VBA: Averiguar rápidamente la versión de Access


            Leer más

            Deja una respuesta Cancelar la respuesta

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

            ETIQUETAS

            Access API ComboBox Consultas CountOfDeclarationLines CountOfLines DCount Diseño DoCmd Excel Fecha FileExists FileSystemObject Filtros Formulario Formularios Funciones Funciones de dominio GetFolder Informes Kill Left Listbox Matrices Mid Mod Módulos Node ProcCountLines Procedimientos ProcOfLine References Replace Ribbon Right RunCommand Split Tablas Tempvars TreeView TwipsFromFont VBA VBE VBIDE WizHook

            ÚLTIMAS ENTRADAS

            • 0
              VBA: Conversor de moneda
              27/09/2023
            • 0
              VBA: Convertir macros a VBA
              26/09/2023

            ¿QUIERES PUBLICITAR TU EMPRESA AQUÍ?

            SUSCRÍBETE A NUESTRO
            NEWSLETTER

            Recibirás información puntual sobre el mundo de Access y VBA

            ¡Próximamente!

            Promovemos el uso de Access y de la programación en VBA en todo el mundo

            Centro de conocimiento


            Toda la sabiduría de los mejores programadores de Access y VBA a tu alcance.

            Legal

            Política de privacidad

            Condiciones de uso

            Condiciones del redactor

            ®Access Global 2021 | All right reserved
                      No hay resultados Mostrar todos los resultados