Skip to content

Instantly share code, notes, and snippets.

@larsschenk
Last active December 31, 2019 15:41
Show Gist options
  • Save larsschenk/70da0380cabb1dc76c194cc7bcea89c8 to your computer and use it in GitHub Desktop.
Save larsschenk/70da0380cabb1dc76c194cc7bcea89c8 to your computer and use it in GitHub Desktop.
Visual Basic for Application examples using the ActiveBarcode REST API with Excel
' There is one Button (CommandButton1) and one Image (Image1) in the sheet.
' If you click on the button, the value of the active cell is displayed as barcode in the image.
' Since LoadPicture cannot use PNG, JPG is used here.
'
Private Declare Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" _
(ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
Private Sub CommandButton1_Click()
strURL = "https://api.activebarcode.net/v1/jpg?access=YOUR-KEY-HERE"
strParam = "&code=CODE128&text=" & Cells(ActiveCell.Row, ActiveCell.Column).Value
strFile = Environ("TEMP") & "\barcodeapi-temp.jpg"
result = URLDownloadToFile(0, strURL & strParam, strFile, 0, 0)
Image1.Picture = LoadPicture(strFile)
Kill strFile
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment