Sie sind auf Seite 1von 5

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Range("Tabla1").Select
Selection.ClearContents
Range("Tabla1").ClearContents
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

On Error GoTo ErrorHandler:

Dim error As Boolean


Dim err_cnt As Integer
Dim err_str As String
err_cnt = 0
err_str = ""

Dim lRowA As Integer

lRowA = Range("A1").End(xlDown).Row
'lRowB = Range("B1").End(xlDown).Row
'lRowC = Range("C1").End(xlDown).Row

Dim arr(1 To 1, 1 To 2)
arr(1, 1) = lRowA
arr(1, 2) = 1
'arr(2, 1) = lRowB
'arr(2, 2) = 2
'arr(3, 1) = lRowC
'arr(3, 2) = 3
'arr(4, 1) = lRowA
'arr(4, 2) = 4

'Limite maximo de lineas


Dim i As Integer
Dim msgerr, flag As Boolean

msgerr = False
flag = False

'For i = 1 To 3
' If arr(i, 1) > 1001 Then
' msgerr = True
' error = True
'flag = True
'err_cnt = err_cnt + 1
'End If
'If arr(i, 1) <> arr(i + 1, 1) Then
'error = True
'flag = True
'err_cnt = err_cnt + 1
'End If
'Next i

If lRowA > 1001 Then


error = True
err_cnt = err_cnt + 1
MsgBox "El límite máximo de líneas es 1000"
End If
If msgerr Then
MsgBox "El límite máximo de líneas es 1000"
End If
'Caracteres especiales, remove red filling

Dim m, k As Integer
Dim spchar(1 To 25) As String
Dim strval As String

spchar(1) = "ñ"
spchar(2) = "á"
spchar(3) = "í"
spchar(4) = "ó"
spchar(5) = "ú"
spchar(6) = "/"
spchar(7) = "*"
spchar(8) = "^"
spchar(9) = "#"
spchar(10) = "$"
spchar(11) = "%"
spchar(12) = "&"
spchar(13) = "?"
spchar(14) = "'"
spchar(15) = "¿"
spchar(16) = "¡"
spchar(17) = "|"
spchar(18) = "°"
spchar(19) = "¬"
spchar(20) = ","
spchar(21) = "}"
spchar(22) = "{"
spchar(23) = "["
spchar(24) = "]"
spchar(25) = "\"

For k = 2 To lRowA

For m = 1 To 25
strval = LCase(Cells(k, 1).Value)
err_char = InStr(strval, spchar(m))
If err_char <= 0 And Cells(k, 1).Interior.ColorIndex = 22 Then
Cells(k, 1).Interior.ColorIndex = 2
End If
Next m

Next k

'Campos vacíoS

Dim gtnum, diffT, j, a As Integer


gtnum = 0
err_str = err_str & vbNewLine

If flag Then
For j = 1 To lRowA
If arr(j, 1) > gtnum Then
gtnum = arr(j, 1)
End If
Next j
For j = 1 To 3
If arr(j, 1) < gtnum Then
diffT = gtnum - arr(j, 1)
For a = arr(j, 1) To arr(j, 1) + diffT
If Cells(a, arr(j, 2)).Value = "" Then
error = True
err_cnt = err_cnt + 1
Cells(a, arr(j, 2)).Interior.ColorIndex = 22
err_str = err_str & " " & Split(Cells(1, arr(j, 2)).Address(True,
False), "$")(0) & a & " "
End If
Next a
End If
Next j
End If

For i = 2 To gtnum
If Cells(i, 1).Value = "" Then
Cells(i, 1).Interior.ColorIndex = 22
err_str = err_str & "A" & i & " "
err_cnt = err_cnt + 1
Else
Cells(i, 1).Interior.ColorIndex = 2
End If
If Cells(i, 2).Value = "" Then
Cells(i, 2).Interior.ColorIndex = 22
err_str = err_str & "B" & i & " "
err_cnt = err_cnt + 1
Else
If IsNumeric(Cells(i, 2).Value) Then
Cells(i, 2).Interior.ColorIndex = 2
Else
Cells(i, 2).Interior.ColorIndex = 22
err_str = err_str & "B" & i & " "
err_cnt = err_cnt + 1
End If
End If
If Cells(i, 3).Value = "" Then
Cells(i, 3).Interior.ColorIndex = 22
err_str = err_str & "C" & i & " "
err_cnt = err_cnt + 1
Else
If IsNumeric(Cells(i, 3).Value) Then
Cells(i, 3).Interior.ColorIndex = 2
Else
Cells(i, 3).Interior.ColorIndex = 22
err_str = err_str & "C" & i & " "
err_cnt = err_cnt + 1
End If
End If
Next i

'Validar formato de TD
Dim str1 As String

err_str = err_str & vbNewLine

For i = 2 To lRowA
str1 = Split(Cells(i, 1).Value, ".")(0)
str2 = Split(Cells(i, 1).Value, ".")(1)

If IsNumeric(str1) Or Not (Len(str1) = 3 Or Len(str1) = 4) Or Not


IsNumeric(str2) Then
err_cnt = err_cnt + 1
err_str = err_str & " " & "A" & i & " "
error = True
Cells(i, 1).Interior.ColorIndex = 22
Else
Cells(i, 1).Interior.ColorIndex = 2
End If
Next i
'caracteres especiales

err_str = err_str & vbNewLine

For k = 2 To lRowA
For l = 1 To 3
For m = 1 To 25
Cells(k, l) = Replace(Cells(k, l).Value, ",", "")
Cells(k, l) = Replace(Cells(k, l).Value, " ", "")
strval = LCase(Cells(k, l).Value)
err_char = InStr(strval, spchar(m))
If err_char > 0 Then
Cells(k, l) = Replace(Cells(k, l).Value, ",", "")
Cells(k, l).Interior.ColorIndex = 22
error = True
err_cnt = err_cnt + 1
err_str = err_str & " " & Split(Cells(1, l).Address(True, False),
"$")(0) & k & " "
End If
Next m
Next l
Next k

If Not error Then


For a = 1 To lRowA
Cells(a, 2).Value = ";"
Next a
Dim wbkExport As Workbook
Dim shtToExport As Worksheet
Dim wbkpath, wbkname, prefix, suffix As String
wbkname = ""
prefix = Format(Now, "yyyymmddhhmmss")
wbkname = "TD-BULK-ACTIVE-" & prefix
suffix = InputBox("Ingrese su código de Usuario de T24." & vbNewLine & "Ej.
HN00000 " & vbNewLine & "Caracterés no aceptados : <> ? : | ° ¬ ~ ´ ' ¿¡ *^ ")
If LCase(Left(suffix, 2)) = "hn" And IsNumeric(Right(suffix, 3)) And Not
InStr(suffix, ".") Then
wbkname = wbkname & "-" & suffix
wbkpath = Application.ActiveWorkbook.Path & "\" & wbkname
Set shtToExport = ThisWorkbook.Worksheets("Principal")
Set wbkExport = Application.Workbooks.Add
shtToExport.Copy Before:=wbkExport.Worksheets(wbkExport.Worksheets.Count)
Application.DisplayAlerts = False
wbkExport.SaveAs Filename:=wbkpath, FileFormat:=xlCSV
Application.DisplayAlerts = True
wbkExport.Close SaveChanges:=False
error = True
Else
error = True
MsgBox "Formato de Usuario de T24 erróneo"
End If
Else
MsgBox "Los errores han sido señalados." & vbNewLine & "Existe(n) " & err_cnt &
" error(es)." & vbNewLine & "No podrá guardar el archivo" & vbNewLine & "hasta
corregir los errores."
MsgBox "Los errores se encuentran en las siguientes casillas:" & vbNewLine &
err_str & vbNewLine & "Para copiar el mensaje de error: Ctrl+c"
End If

Cancel = error

Exit Sub

ErrorHandler:
MsgBox "No puede dejar la columna vacía"
Cancel = True

End Sub

Private Sub Workbook_Open()


MsgBox "Bienvenido a la activación masiva de Tarjetas de Débito" & vbNewLine &
"Porfavor no utilizar el copiado y pegado de texto, dicha acción eliminará" &
vbNewLine & "las validaciones que garantizan que el registro llegue sin problemas a
T24"
End Sub

Function min(a As Integer, b As Integer, c As Integer, d As Integer) As Integer


Dim gtnum As Integer
If a > b Then
gtnum = a
End If

If c > gtnum Then


gtnum = c
End If

If d > gtnum Then


gtnum = d
End If

min = gtnum
End Function

Das könnte Ihnen auch gefallen