Below you can see an example written in VB Script that starts the Word application and inserts a barcode into the document.
set app = CreateObject("Word.Application")
Set doc = app.Documents.Add
doc.Activate
app.Selection.Font.Size = 32
app.Selection.Font.Bold = True
app.Selection.TypeText("Hello DataMatrix-ActiveX")
app.Selection.TypeParagraph
app.Selection.TypeParagraph
'create the DataMatrix-ActiveX
Set oShape = app.Selection.InlineShapes.AddOLEObject("DataMatrixAx.DataMatrixCtrl.1")
'get the created object and set properties
oShape.Width = 150
oShape.Height = 150
Set oDataMatrix = oShape.OLEFormat.Object
oDataMatrix.DataToEncode = "1234567"
oDataMatrix.PreferredFormat = 0
doc.SaveAs "C:\test.doc"
doc.Close
app.Quit
set doc = nothing
set app = nothing
MsgBox "Ok"
You can copy this text to Notepad and save it with the .vbs extension and then start this .vbs file. This will
create the file test.doc on disk "C" with a barcode in it.
Besides, you can use it from VBA (Visual Basic for Applications), i.e. from Excel, Word, Access, etc.
|
You can use our DataMatrix ActiveX in a mail-merge document. You should use macros for that.
Const DataFieldIndex = 4
Const BarcodeModule = 5
Const BarcodeMarker = "BarcodePlace"
Const TmpFileName = "c:\A83BF5BA6020.gif"
Dim WithEvents wdapp As Application
Dim barcode As DataMatrixCtrl
Dim ishapeNew As InlineShape
Dim bcRange As Range
Dim bcFound As Boolean
Private Sub Document_Open()
'Get a reference to the Word application to handle mail merge events.
Set wdapp = Application
'create the barcode object and set up properties
Set barcode = CreateObject("DataMatrixAx.DataMatrixCtrl.1")
barcode.PreferredFormat = f16x48
'barcode.BackColor = RGB(255, 0, 0)
End Sub
Private Sub Document_Close()
Set wdapp = Nothing
End Sub
Private Sub wdapp_MailMergeDataSourceLoad(ByVal Doc As Document)
End Sub
Private Sub wdapp_MailMergeBeforeRecordMerge(ByVal Doc As Document, Cancel As
Boolean)
Set bcRange = Doc.Content
bcRange.Find.Execute FindText:=BarcodeMarker, MatchWholeWord:=True
bcFound = bcRange.Find.Found
If bcFound = True Then
'saves a barcode picture
barcode.DataToEncode = Doc.MailMerge.DataSource.DataFields(DataFieldIndex).Value
Dim w, h
Call barcode.GetMatrixSize(BarcodeModule, 1, 1, dmPixels, dmPixels, w, h)
Call barcode.SaveToImageFile(w, h, TmpFileName)
'adds a barcode picture to the Word document
Set ishapeNew = Doc.InlineShapes.AddPicture(TmpFileName, False, True, bcRange)
'deletes the barcode marker
bcRange.Start = bcRange.Start + 1
bcRange.Delete
End If
End Sub
Private Sub wdapp_MailMergeAfterRecordMerge(ByVal Doc As Document)
If bcFound = True Then
'adds the barcode marker
bcRange.InsertBefore (BarcodeMarker)
'delete the barcode picture
ishapeNew.Delete
End If
End Sub
Private Sub wdapp_MailMergeAfterMerge(ByVal Doc As Document, ByVal DocResult As
Document)
Kill (TmpFileName)
End Sub
Here is you can download the source files.
Download
|