Customisation of the Word macros

The PBarcode macro replaces selected text with a barcode picture generated from that text using the code.

St$ = Selection.Text
If Len(St$) < 1 Then
    MsgBox ("Please select text required for barcode")
    GoTo done
    End If

pa = 0
er1 = BarCodew(St$, pa)
If er1 = 0 Then
    WordBasic.EditPasteSpecial DataType:="PICT"
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$)
End If

This code pastes the barcode picture into the existing selected text – thus replacing the text. The macro can easily be edited to paste the picture elsewhere if required, just generating another Selection or cursor point before the WordBasic.EditPasteSpecial DataType:="PICT" line.

The Fbarcode macro replaces selected text with other text returned by the DLL and then selects the new text and changes its font to the current barcode font settings:

St$ = Selection.Text
If Len(St$) < 1 Then
    MsgBox ("Please select text required for barcode")
    GoTo done
    End If
pa = 0
so$ = String(200, " ")
fo$ = String(36, " ")
er1 = BarCodewF(ByVal St$, pa, ByVal so$, ByVal fo$, fht)
If er1 > 0 Then
    Selection.Text = Left(so$, er1)
    Selection.Font.Name = fo$
    Selection.Font.Size = fht
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$)
End If
done:

Again the barcode text returned in Left(so$,er1) can be inserted elsewhere if required.

 

More:

Mail-merge