EAN EN EXCEL
FMIGUEL
-
eriiic Mensajes publicados 24581 Fecha de registro Estado Colaborador Última intervención -
eriiic Mensajes publicados 24581 Fecha de registro Estado Colaborador Última intervención -
Hola,
Soy novato y estoy intentando convertir una serie de 13 números en un código de barras en Excel. A pesar de todas las ayudas en este sitio: http://grandzebu.net/index.php?page=/informatique/codbar/ean13.htm, no consigo implementar la siguiente macro en Excel:
Public Function ean13$(chaine$)
'Esta función está regida por la Licencia Pública General Reducida GNU (GNU LGPL)
'This function is governed by the GNU Lesser General Public License (GNU LGPL)
'V 1.1.1
'Parámetros: una cadena de 12 números
'Parameters: a 12 digits length string
'Retorno: * una cadena que, al mostrarse con la fuente EAN13.TTF, da el código de barras
' * una cadena vacía si el parámetro proporcionado es incorrecto
'Return: * a string which gives the bar code when it is displayed with EAN13.TTF font
' * an empty string if the supplied parameter is no good
Dim i%, checksum%, first%, CodeBarre$, tableA As Boolean
ean13$ = ""
'Verificar que hay 12 caracteres
'Check for 12 characters
If Len(chaine$) = 12 Then
'Y que son realmente números
'And they are really digits
For i% = 1 To 12
If Asc(Mid$(chaine$, i%, 1)) < 48 Or Asc(Mid$(chaine$, i%, 1)) > 57 Then
i% = 0
Exit For
End If
Next
If i% = 13 Then
'Cálculo de la clave de control
'Calculation of the checksum
For i% = 12 To 1 Step -2
checksum% = checksum% + Val(Mid$(chaine$, i%, 1))
Next
checksum% = checksum% * 3
For i% = 11 To 1 Step -2
checksum% = checksum% + Val(Mid$(chaine$, i%, 1))
Next
chaine$ = chaine$ & (10 - checksum% Mod 10) Mod 10
'El primer número se toma tal cual, el segundo viene de la tabla A
'The first digit is taken just as it is, the second one comes from table A
CodeBarre$ = Left$(chaine$, 1) & Chr$(65 + Val(Mid$(chaine$, 2, 1)))
first% = Val(Left$(chaine$, 1))
For i% = 3 To 7
tableA = False
Select Case i%
Case 3
Select Case first%
Case 0 To 3
tableA = True
End Select
Case 4
Select Case first%
Case 0, 4, 7, 8
tableA = True
End Select
Case 5
Select Case first%
Case 0, 1, 4, 5, 9
tableA = True
End Select
Case 6
Select Case first%
Case 0, 2, 5, 6, 7
tableA = True
End Select
Case 7
Select Case first%
Case 0, 3, 6, 8, 9
tableA = True
End Select
End Select
If tableA Then
CodeBarre$ = CodeBarre$ & Chr$(65 + Val(Mid$(chaine$, i%, 1)))
Else
CodeBarre$ = CodeBarre$ & Chr$(75 + Val(Mid$(chaine$, i%, 1)))
End If
Next
CodeBarre$ = CodeBarre$ & "*" 'Añadir separador central / Add middle separator
For i% = 8 To 13
CodeBarre$ = CodeBarre$ & Chr$(97 + Val(Mid$(chaine$, i%, 1)))
Next
CodeBarre$ = CodeBarre$ & "+" 'Añadir la marca de fin / Add end mark
ean13$ = CodeBarre$
End If
End If
End Function
¿Podrías indicarme la manipulación para que pueda ver aparecer en mi tabla este maldito código de barras?
De antemano, gracias por tu ayuda
Fmiguel
Soy novato y estoy intentando convertir una serie de 13 números en un código de barras en Excel. A pesar de todas las ayudas en este sitio: http://grandzebu.net/index.php?page=/informatique/codbar/ean13.htm, no consigo implementar la siguiente macro en Excel:
Public Function ean13$(chaine$)
'Esta función está regida por la Licencia Pública General Reducida GNU (GNU LGPL)
'This function is governed by the GNU Lesser General Public License (GNU LGPL)
'V 1.1.1
'Parámetros: una cadena de 12 números
'Parameters: a 12 digits length string
'Retorno: * una cadena que, al mostrarse con la fuente EAN13.TTF, da el código de barras
' * una cadena vacía si el parámetro proporcionado es incorrecto
'Return: * a string which gives the bar code when it is displayed with EAN13.TTF font
' * an empty string if the supplied parameter is no good
Dim i%, checksum%, first%, CodeBarre$, tableA As Boolean
ean13$ = ""
'Verificar que hay 12 caracteres
'Check for 12 characters
If Len(chaine$) = 12 Then
'Y que son realmente números
'And they are really digits
For i% = 1 To 12
If Asc(Mid$(chaine$, i%, 1)) < 48 Or Asc(Mid$(chaine$, i%, 1)) > 57 Then
i% = 0
Exit For
End If
Next
If i% = 13 Then
'Cálculo de la clave de control
'Calculation of the checksum
For i% = 12 To 1 Step -2
checksum% = checksum% + Val(Mid$(chaine$, i%, 1))
Next
checksum% = checksum% * 3
For i% = 11 To 1 Step -2
checksum% = checksum% + Val(Mid$(chaine$, i%, 1))
Next
chaine$ = chaine$ & (10 - checksum% Mod 10) Mod 10
'El primer número se toma tal cual, el segundo viene de la tabla A
'The first digit is taken just as it is, the second one comes from table A
CodeBarre$ = Left$(chaine$, 1) & Chr$(65 + Val(Mid$(chaine$, 2, 1)))
first% = Val(Left$(chaine$, 1))
For i% = 3 To 7
tableA = False
Select Case i%
Case 3
Select Case first%
Case 0 To 3
tableA = True
End Select
Case 4
Select Case first%
Case 0, 4, 7, 8
tableA = True
End Select
Case 5
Select Case first%
Case 0, 1, 4, 5, 9
tableA = True
End Select
Case 6
Select Case first%
Case 0, 2, 5, 6, 7
tableA = True
End Select
Case 7
Select Case first%
Case 0, 3, 6, 8, 9
tableA = True
End Select
End Select
If tableA Then
CodeBarre$ = CodeBarre$ & Chr$(65 + Val(Mid$(chaine$, i%, 1)))
Else
CodeBarre$ = CodeBarre$ & Chr$(75 + Val(Mid$(chaine$, i%, 1)))
End If
Next
CodeBarre$ = CodeBarre$ & "*" 'Añadir separador central / Add middle separator
For i% = 8 To 13
CodeBarre$ = CodeBarre$ & Chr$(97 + Val(Mid$(chaine$, i%, 1)))
Next
CodeBarre$ = CodeBarre$ & "+" 'Añadir la marca de fin / Add end mark
ean13$ = CodeBarre$
End If
End If
End Function
¿Podrías indicarme la manipulación para que pueda ver aparecer en mi tabla este maldito código de barras?
De antemano, gracias por tu ayuda
Fmiguel
Configuración: Windows XP Internet Explorer 7.0