I have the following code that I am hoping to get working. The code will check for available DYMO printers and print the label. You are to create a template label and I saved mine as template.label. In that template label I have a text field referenced as TEXT1.
The followin is the code:
Dim myDymo As Object
Dim myLabel As Object
Dim sPrinters As String
Dim arrPrinters() As String
Dim i As Long, i2 As Long, iStart As Long
On Error Resume Next
myDymo = CreateObject("Dymo.DymoAddIn")
myLabel = CreateObject("Dymo.DymoLabels")
If (myDymo Is Nothing) Or (myLabel Is Nothing) Then
MsgBox("Unable to create OLE objects")
Exit Sub
End If
'Check forDymo printer(s)
'If there is one proceed and store the printernames in a variable, else quit
sPrinters = myDymo.GetDymoPrinters()
If sPrinters = "" Then
Exit Sub
Else
i2 = 0
iStart = 1
For i = 1 To Len(sPrinters)
If Mid(sPrinters, i, 1) = "|" Then
i2 = i2 + 1
ReDim Preserve arrPrinters(i2 + 1)
arrPrinters(i2) = Mid(sPrinters, iStart, i - iStart)
iStart = i + 1
End If
Next i
End If
With myDymo
'0 is first Dymo printer, you could use the printername instead: SelectPrinter "YourPrintername"
.SelectPrinter(arrPrinters(0))
End With
'Open the label template
Dim LabelPathString As String = CurDir() & "\Docs\template.label"
myLabel = myDymo.Open(LabelPathString)
'Give text object TEXT1 on the label a value
With myLabel
'.textobject("TEXT1", "Text to be displayed")
.setObjectText("TEXT1", "Text to be displayed")
'.SetField("TEXT1", "Text to be displayed")
End With
'Print the label
With myDymo
.Print(2, False) ' Print 2 copies
End With
'Clean up
myLabel = Nothing
myDymo = Nothing
It sends the print job to the DYMO printer, but the label advances with no text on it. If anyone could help, that would be great. Thanks.
P.S. I have tried these 3 options in the code, but none seem to work:
With myLabel
'.textobject("TEXT1", "Text to be displayed")
.setObjectText("TEXT1", "Text to be displayed")
'.SetField("TEXT1", "Text to be displayed")
End With