Repeated from VB.Net thread...

I've managed to create a work around for this issue and can now print to the printer using the universal driver for the Zebra printer. Now I think I either have a code issue or there is a command that I am not issuing to the printer.

When I first send from Excel the print out is correct. If I stay in the Excel instance and try to print again I either get nothing out of the printer, or I get every other output printed. I.e. the normal expected sequence is 1,2,3,4 what I'm getting is 1,3,5. This is highly annoying as it works fine if I close Excel and open it again OR I cycle power on the printer.

Some variable somewhere is gumming up the works and I can't figure it out.

I've used the msgbox in place of the printout command and the logic appears to work fine (increments correctly). I've built the command string and saved it to Cell $A$1 to a spreadsheet and then used the printout command to send it to the printer. I've added the pass through symbols to the string that allow the command string to go directly to the printer. Can anyone spot what I'm doing wrong?

Code:
Private Sub CommandButton1_Click()
'check text box values and pass values to main module
sl = StartLabel.Text
el = EndLabel.Text
Site = Site.Text
    If Len(sl) = 0 Or Len(el) = 0 Then
        MsgBox "Please enter Start and End values"
        Exit Sub
    End If
    If Len(Site) = 0 Then
        ans = MsgBox("Are you sure that you do not want to enter a Site name?" & Chr(13) & "The Default 'E-Team' will be printed without a site name", vbYesNo, "Site Name?")
        If ans = vbNo Then Exit Sub
    End If
    
' label formatting commands
s = "^XA^PR2~SD30" ' start of label format
f = "^XZ" ' end of label format
O1 = "^FO0,20" ' origin ^FOx,y
O2 = "^FO40,78" ' origin ^FOx,y
O3 = "^FO0,150" ' origin ^FOx,y
F1 = "^AUN,62,7" ' field 1 font
F2 = "^B3N,,62,N" ' Barcode font
F3 = "^ADN,36,4" ' site name font
DS = "^FD" 'data field start
DE = "^FS" 'data field seperator
FB = "^FB400,1,0,C,0" ' Fields (F1 & F3) needs this at the beginning

''Loop resolution
Call lpcnt(sl, el, sv, svl, ev, evl, lp)
iter = lp' number of labels to print
MsgBox lp & " Labels will be printed." & Chr(13) & "Starting at " & sl & " and ending at " & el & "."
nl = sl
'build and print labels
For I = 1 To iter

Str1 = "${" & s & O1 & F1 & FB & DS & nl & DE ' Start of format data
Str2 = O2 & F2 & DS & nl & DE ' Barcode portion of label
Str3 = O3 & F3 & FB & DS & "E-TEAM/" & Site & f & "}$" 'end of format data
Worksheets("LabelData").Range("$A$1") = Str1 & Str2 & Str3 ' build and save command codes

'************************************************
Worksheets("LabelData").Range("$A$1").PrintOut ' send data to passthrough on driver
'Repeat until all labels are printed

' nl = next label, sv1 = length of non number start label
' lz = leading zeros, nv = next value string
    x = Len(nl)
    For Y = 1 To Len(nl)' find numerical start
        If Val(Mid(nl, Y, 1)) = 0 And Mid(nl, Y, 1) <> "0" Then x = x - 1
    Next Y
    nvn = Val(Right(nl, x)) + 1 ' next value number
    nvl = Len(nl) - x ' length of numbers string, x = length of non number string
nv = CStr(nvn) ' next value string
If Len(CStr(nv)) < nvl Then
    lz = ""
    For h = 1 To (Len(nl) - (x + Len(nv)))' add leading zeros to rebuild label string
        lz = lz & "0"
    Next h
End If
    nl = Left(nl, x) & lz & nv
Next I
Call UserForm_Initialize
End Sub
Private Sub lpcnt(sl, el, sv, svl, ev, evl, lp)
'Determine numeric start value
    x = Len(sl)
    For I = 1 To Len(sl)
        If Val(Mid(sl, I, 1)) = 0 And Mid(sl, I, 1) <> "0" Then x = x - 1
    Next I
sv = Val(Right(sl, x))
svl = Len(sl) - x
'Determine numeric end value
    x = Len(el)
    For I = 1 To Len(el)
        If Val(Mid(el, I, 1)) = 0 And Mid(el, I, 1) <> "0" Then x = x - 1
    Next I
ev = Val(Right(el, x))
evl = Len(el) - x
' Calculate number of labels to be printed.
lp = ev - sv + 1

End Sub