Вы находитесь на странице: 1из 6

Buscar palabra Function BuscarTexto(Texto As String, Busqueda As String) As Boolean Dim i As Integer i = InStr(1, Texto, Busqueda) If i > 0 Then

BuscarTexto = True Else BuscarTexto = False End If End Function

Busqueda numeros: Si no las conoces, te recomiendo que entres en esta web: Regular-Expressions.info - Regex Tutorial, Examples and Reference - Regexp Patte rns Y leas los tutoriales que hay. Te van a simplificar el trabajo en multitud de oc asiones de una forma impresionante. Son una cosa que merece la pena conocer. Para hacer uso de las expresiones regulares, has de importar el Namespace System .Text.RegularExpressions y luego con un cdigo similar a ste: Cdigo: Dim oRegEx As Regex Dim oResultado As Match Dim aoCoincidencias As MatchCollection 'Creamos una expresin regular con el patrn especificado oRegEx = New Regex(strPatronACumplir) 'Obtenemos todas las coincidencias del texto de entrada en base al patrn aoCoincidencias = oRegEx.Matches(strTextoAEvaluar) 'Recorremos todas las coincidencias y vamos mostrndolas en la lista For Each oResultado In aoCoincidencias 'Aqu iras haciendo lo que tengas que hacer con cada ocurrencia encontrada, 'a las cuales puedes acceder as: oResultado.ToString Next oResultado De esta forma, simplemente cambiando el patrn, puedes ir haciendo todo tipo de bsq uedas en el texto, desde las ms sencillas, hasta las ms rebuscadas. Para buscar dgitos sueltos, podras usar el siguiente patrn: "\d" * Ej: "23 m4 7,29" devolvera lo siguiente: Cdigo: 2 3 4 7 2

9 Y para buscar nmeros compuestos por ms de un dgito, el siguiente: "\d+" * Ej: "23 m4 7,29" devolvera lo siguiente: Cdigo: 23 4 7 29 Segn lo que necesites, tendrs que usar un patrn u otro.

Llamadas funciones: linea = crearValidacionRutinaRegalos(Trim(Range("C" & i).Value), i) Function crearValidacionRutinaContratacion(valor, i) As String crearValidacionRutinaContratacion = strCadenaFinal End Function crearValidacionRutinaContratacion = strCadenaFinal Function crearValidacionRutinaContratacion(valor, i) As String crearValidacionRutinaContratacion = strCadenaFinal End Function

Ver Dim Dim Dim

original Texto As String sTexto() As String Looping As Byte

Texto = "tambor plastico por 227 Kg" 'Convertir la cadena en un arreglo, usando como separador el espacio " " sTexto = Split(Texto, " ") 'Recorrer todos los elementos obtenidos For Looping = 0 To UBound(sTexto) 'Si es numrico salir del bucle If IsNumeric(sTexto(Looping)) Then Exit For Next Looping MsgBox sTexto(Looping)

Ver original Dim regExp As Object Dim Texto As String Texto = "Cualquier texto con numeros 125" Set regExp = CreateObject("VBScript.RegExp") regExp.Pattern = "(\d+)"

If regExp.Test(Texto) Then MsgBox regExp.Execute(Texto)(0).Value End If Set regExp = Nothing system(cadena) [1:14:06] David Sanz: Generacion par1 par2 par3 [1:14:14] David Sanz: system("cadena") if (strstr(mystring,"LINKAGE SECTION.")!=NULL) Option Explicit Dim strRuta As String Public Sub SelecFichero() Dim Selector As CommonDialog Dim bEncontrado As Boolean Dim bErrorRutaVacia As Boolean Dim strAux As String On Error GoTo eError ' ' ' ' Set Selector = New CommonDialog Selector.Filter = "Archivo .COB|*.cob" Selector.ShowOpen strRuta = Selector.Filename strRuta = "C:\Users\Vanesa\Desktop\HardCodes\Prueba.cob" Me.Cells(5, "F").Value = strRuta bErrorRutaVacia = False Exit Sub eError: If bErrorRutaVacia = True Then MsgBox "Debe seleccionar un fichero" Else MsgBox "ERROR de la Aplicacin" End If End Sub Public Sub LimpiaFichero() Dim foo As Integer Dim sLineaTemp As String Dim sContenido As String If strRuta = "" Then MsgBox "No se ha seleccionado ningn fichero" Exit Sub Else foo = FreeFile

Open strRuta For Input As #foo Do While Not EOF(foo) Line Input #foo, sLineaTemp If Trim(sLineaTemp) <> "" Then sContenido = sContenido & sLineaTemp & vbCrLf End If Loop Close #foo foo = FreeFile Open strRuta For Output As #foo Print #foo, sContenido Close #foo Me.Cells(5, "F").Value = "" End If End Sub Public Sub ComentarHardCodes() Dim Dim Dim Dim Dim foo As Integer sLineaTemp As String sContenido As String HardCode As String Bloqueo As Integer

'eliminar strRuta = "C:\Users\Vanesa\Desktop\HardCodes\Prueba.cob" If strRuta = "" Then MsgBox "No se ha seleccionado ningn fichero" Exit Sub Else foo = FreeFile Open strRuta For Input As #foo Bloqueo = 0 Do While Not EOF(foo) Line Input #foo, sLineaTemp Do While Bloqueo = 0 If Trim(Mid(sLineaTemp, 7, 66)) = "LINKAGE SECTION." Then Bloqueo = 1 End If sContenido = sContenido & sLineaTemp & vbCrLf Line Input #foo, sLineaTemp Loop 'Aadir caso linea vacia enter If Mid(sLineaTemp, 7, 1) = "*" Or InStr(1, Mid(sLineaTemp, 8, 65 ), "'") < 0 Or EOF(foo) Then sContenido = sContenido & sLineaTemp & vbCrLf Else HardCode = BuscarHardcode(Mid(sLineaTemp, 8, 65)) If Right(HardCode, 1) <> "'" Then Line Input #foo, sLineaTemp

HardCode = HardCode & Mid(sLineaTemp, 8, InStr(8, sLinea Temp, "'")) End If 'seguir MsgBox HardCode End If Loop Close #foo foo = FreeFile Open strRuta For Output As #foo Print #foo, sContenido Close #foo Me.Cells(5, "F").Value = "" End If MsgBox "Yata!" End Sub Function BuscarHardcode(Texto As String) As String Dim IniHard As Integer Dim FinHard As Integer Dim HardCode As String IniHard = InStr(1, Texto, "'") If InStr(IniHard + 1, Texto, "'") > 0 Then FinHard = InStr(IniHard + 1, Texto, "'") Else FinHard = 66 End If BuscarHardcode = Mid(Texto, IniHard, FinHard - IniHard + 1) End Function

Puedes probar algo as para crear un TXT Set fs = CreateObject("Scripting.FileSystemObject") Set a = fs.CreateTextFile("C:\Prueba.txt", True) a.WriteLine "02076637440K001 Que se Yo" a.WriteLine " " a.WriteLine "3 de Marzo" a.Close

Otra manera tratamineto ficheros Dim UltFila As Integer, i As Integer, NroArchivo As Integer UltFila = Range("A65536").End(xlUp).Row

If Dir("c:\pruebaxx.txt") = "" Then MsgBox "El archivo txt no existe", 64, "Todo Excel" Exit Sub End If NroArchivo = FreeFile Open "c:\pruebaxx.txt" For Output As #NroArchivo For i = 1 To UltFila Print #1, 1; Range("A" & i).Value & Chr(9) & Range("B" & i).Value & Chr(9) & Range("C" & i).Value Next i Close #1 1) el siguiente ejemplo va agregando lineas en un archivo de texto [p.e. cada ve z que se ejecute la impresion POR TU BOTON] y permite que, independientemente del numero_factura que le hubieran puesto, pue des consultar el numero de lineas anteriores ;) inicio de codigo ==Sub Grabar_registro_nuevo() Dim Grabacion As Integer: Grabacion = FreeFile Open "c:\windows\system\ctrlfl.txt" For Append As #Grabacion Print #Grabacion, Worksheets("formatofactura").Range("a3") Close #Grabacion End Sub

For i = 1 To libros tramo = tramo + 30 Open "Ruta" & i & ".txt" For Output As #i

Вам также может понравиться