Skip to content

Instantly share code, notes, and snippets.

@larsschenk
Last active December 31, 2019 15:45
Show Gist options
  • Save larsschenk/dac66822b9d8b6ffca6b253909d72a8b to your computer and use it in GitHub Desktop.
Save larsschenk/dac66822b9d8b6ffca6b253909d72a8b to your computer and use it in GitHub Desktop.
Visual Basic for Application examples using the ActiveBarcode REST API with Word
' A button (CommandButton1), an image (Image1) and a form field (Text1) are in a document.
' If you click on the button, the value from the form field is displayed as a barcode in the image. (*)
' Since LoadPicture cannot use PNG, JPG is used here.
'
' (*) this can also be automated.
'
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=" & ActiveDocument.FormFields("Text1").Range.Text
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