Last active
December 31, 2019 15:45
-
-
Save larsschenk/dac66822b9d8b6ffca6b253909d72a8b to your computer and use it in GitHub Desktop.
Visual Basic for Application examples using the ActiveBarcode REST API with Word
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' 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