By default the PBarcode macro centres each barcode image over the cell adjacent to its data source cell using the cellcolumn1 value as shown below (where cellcolumn is the column that contains the source data). The height of the row is adjusted to be 120% of the barcode image height. By editing the code the barcode position can be customised.
cellcolumn1 = cellcolumn + 1
St$ = (Cells(cellrow,
cellcolumn).Text)
If Len(St$) = 0 Then ' skip empty
cells
Barcode = -1
GoTo
done
End If
'
i = 0
er1 = BarCodew(ByVal St$,
i)
If er1 = 0 Then
Cells(cellrow,
cellcolumn1).ClearContents
Cells(cellrow,
cellcolumn1).Select
Cells(cellrow,
cellcolumn1).Interior.ColorIndex = xlNone
Set px =
ActiveSheet.Pictures.Paste
Cells(cellrow,
cellcolumn1).RowHeight = px.Height * 1.2 ' cell heights are in points; this is
20% larger than barcode height
px.Border.LineStyle =
xlNone
' centre barcode image in the
cell
ih = (Cells(cellrow, cellcolumn1).Height - px.Height)
/ 2
iw = (Cells(cellrow, cellcolumn1).Width - px.Width) /
2
px.Left = Cells(cellrow, cellcolumn1).Left +
iw
px.Top = Cells(cellrow, cellcolumn1).Top +
ih
Barcode = -1
Else
If er1 = 1
Then
x$ = "Wrong number of
characters in barcode"
ElseIf er1 = 4
Then
x$ = "Illegal character in
barcode data"
Else
x$ = "Error in barcode
data"
End If
MsgBox
x$
Barcode = 0
End If
done:
The FBarcode macro places the font-based barcode text into the cell adjacent to the data, using the column identifier cellcolumn1% in the code below. The font used for the cell is set to the fontname and height returned from the BarCodewF() call (where it had been stored by the FBarcodeSetup macro)
Out$ = String(120, " ")
Barcode2 = 1
cellcolumn1% =
cellcolumn% + 1 ' edit this line if you want the barcode elsewhere
St$ =
(Cells(cellrow%, cellcolumn%).Text)
Cells(cellrow%,
cellcolumn1%).ClearContents
If Len(St$) = 0 Then ' skip empty
cells
Barcode2 = -1
GoTo
done
End If
fonname$ = String(48, " ")
fonht& = 24
j& =
BarCodewF(ByVal St$, nn&, ByVal Out$, ByVal fonname$, fonht&)
If
(j& > 0) Then
Cells(cellrow%, cellcolumn1%) =
Out$
Cells(cellrow%, cellcolumn1%).Font.Name =
fonname$
Cells(cellrow%, cellcolumn1%).Font.Size =
fonht&
Rows(cellrow%).RowHeight = fonht& *
1.2
Else
If j& = 1
Then
x$ = "Wrong number of
characters in barcode"
ElseIf j& = 4
Then
x$ = "Illegal character in
barcode data"
Else
x$ = "Error in barcode
data"
End If
MsgBox
x$
Barcode2 = 0
End If
done:
The destination cell for the barcode may be changed by editing the cellcolumn1% variable in the code above.
More: