Function Azalea_ISBN13(ByVal ISBNnumber As String, ByVal Price As String) As String ' UPCTools 16may12 jwhiting ' Copyright 2012 Azalea Software, Inc. All rights reserved. www.azaleabarcodes.com ' Creating an ISBN-13 barcode in Excel ' ISBNnumber is a 13-digit ISBN number and Price is the retail price used in the 5-digit supplemental code. ' ISBNnumber has no hyphens or spaces. Strip them out if necessary to make an 11-digit string. Dim ISBN As String ' a bucket for the ISBN string Dim checkDigitSubtotal As Integer ' a check digit subtotal Dim checkDigit As String ' a check digit throwaway Dim temp As String ' a temporary placeholder ' drop the ISBN check digit ISBN = Left(ISBNnumber, 12) ' Let's do the EAN-13 check digit calculation checkDigitSubtotal = 3 * (Val(Mid(ISBN, 2, 1)) + Val(Mid(ISBN, 4, 1)) + Val(Mid(ISBN, 6, 1)) + Val(Mid(ISBN, 8, 1)) + Val(Mid(ISBN, 10, 1)) + Val(Right(ISBN, 1))) checkDigitSubtotal = checkDigitSubtotal + Val(Left(ISBN, 1)) + Val(Mid(ISBN, 3, 1)) + Val(Mid(ISBN, 5, 1)) + Val(Mid(ISBN, 7, 1)) + Val(Mid(ISBN, 9, 1)) + Val(Mid(ISBN, 11, 1)) checkDigit = Right(Str(300 - checkDigitSubtotal), 1) ' Build the output string. ' Does the ISBN number begin with 978 or 979? If Mid(ISBN, 3, 1) = "8" Then temp = Chr(203) + "|xHS" + EvenBar(Mid(ISBN, 4, 1)) Else temp = Chr(203) + "|xHT" + EvenBar(Mid(ISBN, 4, 1)) End If temp = temp + OddBar(Mid(ISBN, 5, 1)) temp = temp + EvenBar(Mid(ISBN, 6, 1)) temp = temp + OddBar(Mid(ISBN, 7, 1)) + "y" + Right(ISBN, 5) + checkDigit + "zv" ' Calculate the 5-digit supplemental check digit checkDigitSubtotal = 3 * (Val(Left(Price, 1)) + Val(Mid(Price, 3, 1)) + Val(Right(Price, 1))) checkDigitSubtotal = checkDigitSubtotal + (9 * (Val(Mid(Price, 2, 1)) + Val(Mid(Price, 4, 1)))) checkDigit = Right(Str(checkDigitSubtotal), 1) ' The rest of the output depends upon the checkDigit value. Select Case checkDigit Case "0" ' EEEOO temp = temp + EvenS(Left(Price, 1)) + ":" + EvenS(Mid(Price, 2, 1)) Azalea_ISBN13 = temp + ":" + OddS(Mid(Price, 3, 1)) + ":" + OddS(Mid(Price, 4, 1)) + ":" + OddS(Right(Price, 1)) Case "1" ' EOEOO temp = temp + EvenS(Left(Price, 1)) + ":" + OddS(Mid(Price, 2, 1)) Azalea_ISBN13 = temp + ":" + EvenS(Mid(Price, 3, 1)) + ":" + OddS(Mid(Price, 4, 1)) + ":" + OddS(Right(Price, 1)) Case "2" ' EOOEO temp = temp + EvenS(Left(Price, 1)) + ":" + OddS(Mid(Price, 2, 1)) Azalea_ISBN13 = temp + ":" + OddS(Mid(Price, 3, 1)) + ":" + EvenS(Mid(Price, 4, 1)) + ":" + OddS(Right(Price, 1)) Case "3" ' EOOOE temp = temp + EvenS(Left(Price, 1)) + ":" + OddS(Mid(Price, 2, 1)) Azalea_ISBN13 = temp + ":" + OddS(Mid(Price, 3, 1)) + ":" + OddS(Mid(Price, 4, 1)) + ":" + EvenS(Right(Price, 1)) Case "4" ' OEEOO temp = temp + OddS(Left(Price, 1)) + ":" + EvenS(Mid(Price, 2, 1)) Azalea_ISBN13 = temp + ":" + EvenS(Mid(Price, 3, 1)) + ":" + OddS(Mid(Price, 4, 1)) + ":" + OddS(Right(Price, 1)) Case "5" ' OOEEO temp = temp + OddS(Left(Price, 1)) + ":" + OddS(Mid(Price, 2, 1)) Azalea_ISBN13 = temp + ":" + EvenS(Mid(Price, 3, 1)) + ":" + EvenS(Mid(Price, 4, 1)) + ":" + OddS(Right(Price, 1)) Case "6" ' OOOEE temp = temp + OddS(Left(Price, 1)) + ":" + OddS(Mid(Price, 2, 1)) Azalea_ISBN13 = temp + ":" + OddS(Mid(Price, 3, 1)) + ":" + EvenS(Mid(Price, 4, 1)) + ":" + EvenS(Right(Price, 1)) Case "7" ' OEOEO temp = temp + OddS(Left(Price, 1)) + ":" + EvenS(Mid(Price, 2, 1)) Azalea_ISBN13 = temp + ":" + OddS(Mid(Price, 3, 1)) + ":" + EvenS(Mid(Price, 4, 1)) + ":" + OddS(Right(Price, 1)) Case "8" ' OEOOE temp = temp + OddS(Left(Price, 1)) + ":" + EvenS(Mid(Price, 2, 1)) Azalea_ISBN13 = temp + ":" + OddS(Mid(Price, 3, 1)) + ":" + OddS(Mid(Price, 4, 1)) + ":" + EvenS(Right(Price, 1)) Case "9" ' OOEOE temp = temp + OddS(Left(Price, 1)) + ":" + OddS(Mid(Price, 2, 1)) Azalea_ISBN13 = temp + ":" + EvenS(Mid(Price, 3, 1)) + ":" + OddS(Mid(Price, 4, 1)) + ":" + EvenS(Right(Price, 1)) End Select ' The output, Azalea_ISBN13, is formatted using one of Azalea Software's UPC fonts. ' Excel: B1=Azalea_ISBN13(A1) ' Or put another way, yourContainer.text=Azalea_ISBN13(yourInputString) End Function Private Function OddS(ByVal theString As String) As String ' UPCTools 16may12 jwhiting ' Copyright 2012 Azalea Software, Inc. All rights reserved. www.azaleabarcodes.com Select Case theString Case "0" OddS = "!" Case "1" OddS = Chr(34) Case "2" OddS = "#" Case "3" OddS = "" Case "4" OddS = "%" Case "5" OddS = "&" Case "6" OddS = "'" Case "7" OddS = "(" Case "8" OddS = ")" Case "9" OddS = "*" End Select End Function Private Function EvenS(ByVal theString As String) As String ' UPCTools 16may12 jwhiting ' Copyright 2012 Azalea Software, Inc. All rights reserved. www.azaleabarcodes.com Select Case theString Case "0" EvenS = "+" Case "1" EvenS = "," Case "2" EvenS = "-" Case "3" EvenS = "." Case "4" EvenS = "/" Case "5" EvenS = ";" Case "6" EvenS = "<" Case "7" EvenS = "=" Case "8" EvenS = ">" Case "9" EvenS = "^" End Select End Function Private Static Function OddBar(ByVal theString As String) As String ' UPCTools 16may12 jwhiting ' Copyright 2012 Azalea Software, Inc. All rights reserved. www.azaleabarcodes.com OddBar = Chr(65 + (Val(theString))) End Function Private Static Function EvenBar(ByVal theString As String) As String ' UPCTools 16may12 jwhiting ' Copyright 2012 Azalea Software, Inc. All rights reserved. www.azaleabarcodes.com EvenBar = Chr(75 + Val(theString)) End Function