Home
SEARCH

 

Using B-Coder with Excel 97 and later


B-Coder Pro works just fine with Excel 97 and 2000 however Excel does not support pasting of standard Windows Metafiles through the clipboard.

If you try to paste a bar code from B-Coder into Excel 97 or later, you will see a bar code appear in the worksheet however it will probably not read correctly when printed. The problem is that Excel will automatically convert metafiles pasted through the clipboard to "Enhanced metafiles". During the conversion process, Excel distorts the widths of the bars and spaces so that they are not the same widths as in the original graphic and therefore, the bar code is rendered unreadable. It turns out that Excel can import Windows metafiles from a disk based metafile correctly therefore the solution to the problem is to import all bar codes through a disk file instead of pasting them through the clipboard.

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 Office 97 or Excel 97, 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 Office 97 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 97 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.

To generate and import a bar code created with B-Coder into an Excel worksheet, perform the following steps:

1. Generate your bar code in B-Coder Pro as you normally would. After your bar code is visible in the B-Coder window, select "Save Bar Code As..." from the FILE menu.

2. In the File Save dialog box, enter a file name for the bar code making sure that you use the file name extension ".WMF". For example, you might use the file name: "BARCODE.WMF". At this point, your bar code now exists on disk as a standard Windows metafile.

3. Open up Excel and select "Picture" and "From File..." in Excel's INSERT menu. When the File Open dialog box appears, locate the file that you saved in B-Coder (i.e. the file BARCODE.WMF), highlight it and click the "Insert" button.

Your bar code should appear in Excel's window and you can place the bar code where you would like it to appear by simply dragging it with your mouse.

Note: Although you can resize the bar code in Excel, it is recommended that you do not change the width of the bar code after you import it into Excel.

The following is an example Excel VBA macro that will generate a bar code by calling B-Coder Pro. The 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.

Download a working Excel spreadsheet example.
 

Sub GenerateBarCode()
  Dim BC$
  Dim Chan As Long

  ' 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 B-Coder." +       Chr(13) _
      & "To use, select a cell containing some text and run this       macro."
    Exit Sub
  End If

  ' Initiate DDE link to B-Coder
  Chan = DDEInitiate("B-Coder", "System")

  ' Turn on print warnings/Message Warnings
  DDEExecute Chan, "[PrintWarnings=on]"
  DDEExecute Chan, "[MessageWarnings=on]"

  ' generate the bar code
  DDEExecute Chan, "[barcode=" + BC$ + "]"

  ' save the bar code to a disk file
  DDEExecute Chan, "[savebarcode(C:\barcode.wmf)]"

  ' Terminate the DDE link
  DDETerminate Chan

  ' insert the bar code picture from the disk file into the sheet
  ActiveSheet.Pictures.Insert("C:\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

Related Links

Special Considerations when Pasting Bar Codes From B-Coder
How a Bar Code Reader Works