Using the ActiveX Control with Excel 97/2000
One important prerequisite to being able to import metafiles is that
you must have a Windows metafile graphics import filter installed for
MS Office. When you install Microsoft Office (or just Microsoft Excel),
you are given the choice of installing using either a "Typical Installation",
a "Custom Installation" or a "Minimum Installation". To install the Windows
metafile graphics import filter, you must choose "Custom Installation"
and then select the Windows metafile Graphics import filter option in
the Graphics Import section of the Microsoft Office setup program.
To check if you already have the Windows metafile graphics import filter
installed, or to install it, perform the following steps:
1. Insert the MS Office CD-ROM in your CD-ROM drive and run the
program: SETUP.EXE located in the root directory of the drive.
2. Select "Add/Remove" from the main setup menu.
3. Highlight the "Converters and Filters" option in the list of
installation options and click the button labeled "Change Options".
4. Highlight the "Graphics Filters" option in the list and click
the button labeled "Change Options".
5. In the bottom of the list that appears, make sure that the option
"Windows Metafile Import" is checked.
6. If the option is already checked then you already have the Windows
metafile graphics import filter installed and you can click the "Cancel"
button until you are returned to the main setup menu where you can click
the "Exit Setup" button to exit.
7. If the "Windows Metafile Import" is not checked then select
it and click the OK button until you are returned to the main Setup Options
list where you can click the "Continue" button to complete the installation.
After the Setup program has completed installing the Windows Metafile
Graphics Import filter, Excel will be able to import standard Windows
metafiles stored on disk.
See Also:
How a Bar Code Reader
Works
The following are example Excel VBA macros that will generate a bar code
using the ActiveX Control. The GenerateBarCode()
macro uses data in the active cell for the bar code message and then inserts
the bar code graphic in the worksheet 100 pixels to the right of the cell
containing the data. The xlLoop()
macro will loop through all the cells in Column A that contain
data and insert a barcode to the right of the cell.
Note: In our example we inserted the ActiveX on a user form called 'frmMain'.
You could instead insert the ActiveX control directly onto your spreadsheet
and set its visible property to false. Then instead of using frmMain.TALBarCd1
you would use Sheet1.TALBarCd1
to set its properties.
Const AXMyPath$ = "C:\"
'Set path to save files temporarily
Sub GenerateBarCode()
Dim BC$
' get a bar code
message from the active cell and put it in a string
BC$ = ActiveCell.Value
' remove any carriage return from bar code message
If Right$(BC$, 1) = Chr(13) Then BC$ = Left$(BC$, Len(BC$) - 1)
' strip off trailing spaces
BC$ = RTrim$(BC$)
' if no text is selected then quit
If Len(BC$) = 0 Then
MsgBox "This macro converts text to a bar code using The TAL Bar
Code ActiveX Control." + vbCr _
& "To use, select a cell containing some text and run this macro."
Exit Sub
End If
' generate the
bar code
frmMain.TALBarCd1.Message = BC$
'save barcode
frmMain.TALBarCd1.SaveBarCode AXMyPath$ & "Barcode.wmf"
' insert the
bar code picture from the disk file into the sheet
ActiveSheet.Pictures.Insert(AXMyPath$ & "Barcode.wmf").Select
'The following
two lines demonstrate how to move the bar code
'picture to the right and down a number of pixels from the cell
'containing the original input data that the bar code was
' generated from.
Selection.ShapeRange.IncrementLeft 100
' Selection.ShapeRange.IncrementTop 50
End Sub
Sub xlLoop()
'
'This is an example of a fairly simple macro that will loop
'through all the cells in a column
'of an Excel Spreadsheet, taking the data and converting it to
'barcodes box beside it.
'
' Last updated April 2001. rob@taltech.com.
' ---------------------------------------------------------------
Dim NumLoops As Long, rowpointer As Long, A, i As Long
ActiveSheet.Cells(1, 1).Select
' start at cell A1 (Row 1, column 1)
'Get last row that contains data (based on last
cell containing
'data in column A):
NumLoops = Cells(65000, 1).End(xlUp).Row
'Initialize
Row Pointer
rowpointer = 0
frmMain.TALBarCd1.BarHeight = 500 'set barheight
to half an inch
For i = 1 To NumLoops
A = ActiveCell.Offset(rowpointer, 0).Value
'take the value of the first field and pass it to
activex
frmMain.TALBarCd1.Message = A
'save barcode with record number
frmMain.TALBarCd1.SaveBarCode AXMyPath$ & "BarcodeA" &
i & ".wmf"
' insert the bar code picture from the disk file
into the sheet
ActiveSheet.Pictures.Insert(AXMyPath$ & "barcodeA" &
i & ".wmf").Select
' The following two lines demonstrate how to move
the bar code
' picture to the right and down a number of pixels from the cell
' containing the original input data that the bar code was
' generated from.
Selection.ShapeRange.IncrementLeft 100
Selection.ShapeRange.IncrementTop (i * 50) - 50
'delete last barcode file
Kill AXMyPath$ & "barcodeA" & i & ".wmf"
'increment row number
rowpointer = rowpointer + 1
Next 'i
End Sub
Click
here to download a working Excel spreadsheet example.
|