Skip to content

Instantly share code, notes, and snippets.

@larsschenk
Last active April 12, 2017 10:53
Show Gist options
  • Save larsschenk/dbf532788124bccb324984601ba33bfb to your computer and use it in GitHub Desktop.
Save larsschenk/dbf532788124bccb324984601ba33bfb to your computer and use it in GitHub Desktop.
Access ActiveBarcode objects from Excel
' Avoid using ActiveSheet in your scripts
' if you are not sure if the active sheet remains active while
' running your VBA script.
' Best practise is to access the ActiveBarcode object via a variable
' That is stored for the whole livecycle of your script.
' Access the ActiveBarcode object without using ActiveSheet is
' shown here:
Public Sub AccessBarcode()
Dim MyBarcode ' Variable to access the barcode
' Change the name of the worksheet and the name of the barcode object if required:
Set MyBarcode = ThisWorkbook.Worksheets("Tabelle1").OLEObjects("Barcode1").Object
' Now you can access the barcode regardles of the active sheet via the variable:
MyBarcode.TypeName = "Code 128"
MyBarcode.Text = "My text"
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment