Barcode Error,Help!

HYKE

Active Member
Joined
Jan 31, 2010
Messages
373
Hi,

I have downloaded an excel VBA barcode generating code but is having issues on this line
Code:
 ActiveSheet.Pictures.Insert(Application.Path & "\Barcode" & CStr(i) & ".wmf").Select

This the full code. Kindly advise as to what needs to be done here.


Thanks!
Code:
Dim Overwrite As Boolean
' Note: You must have a Reference to the "TAL Bar Code Control 1.0" selected
' in the Excel VBA References window. (Select Tools - References in the Excel VBA Editor)
Sub GenerateBarCodes()
'delete all images of bar codes that are already on the sheet
On Error Resume Next        ' ignore errors
For Each x In ActiveSheet.Shapes
   ' only delete pictures - leave button and textbox alone
   If InStr(x.Name, "Picture") Then ActiveSheet.Shapes(x.Name).Delete
Next
ActiveSheet.Cells(1, 1).Select      ' start in cell A1
While Len(ActiveCell.Text)          ' continue down column A until we hit an empty cell
  Overwrite = False                 ' do not overwrite the data in the active cell with the bar code
  GenerateBarCodeInActiveCell       ' call the GenerateBarCodeInActiveCell function
  ActiveCell.Offset(1, 0).Select    ' select the next cell down in the column
Wend
ActiveSheet.Cells(1, 1).Select      ' move back to cell A1
End Sub
Sub GenerateBarCodeInActiveCellOverwrite()
Overwrite = True                    ' overwrite the cell data with the bar code
GenerateBarCodeInActiveCell         ' generate the bar code
End Sub
Sub GenerateBarCodeInActiveCell()
Static i As Long
Dim MyBarCode As Object     ' dim a new Object variable
' create a TAL Bar Code object in memory
Set MyBarCode = CreateObject("talbarcd.talbarcd.1")
MyBarCode.BarHeight = 400        ' set barheight of the bar codes to 400 mils (.4 inches)
MyBarCode.Symbology = bcCode128  ' set the bar code symbology to Code 128
If Len(ActiveCell.Text) Then      ' continue down column A until we hit an empty cell
  i = i + 1                       ' increment a counter variable to be used in the file name
  ' set the message property of the bar code to the data in the active cell
  MyBarCode.Message = ActiveCell.Value
  'save barcode to a unique file name as a Windows metafile
  MyBarCode.SaveBarCode Application.Path & "\Barcode" & CStr(i) & ".wmf"
  
  
  If Not Overwrite Then ActiveCell.Offset(0, 1).Select  ' select the cell next to the current cell
  
  ' insert the bar code picture from the disk file into the sheet at the current cell location
  ActiveSheet.Pictures.Insert(Application.Path & "\Barcode" & CStr(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 2
  Selection.ShapeRange.IncrementTop 2
  
  'delete last barcode file
  Kill Application.Path & "\Barcode" & CStr(i) & ".wmf"
  ' select the next cell down in column A
  If Not Overwrite Then ActiveCell.Offset(0, -1).Select
  
Else
  MsgBox "Please enter some data in the active cell to be encoded in a bar code."
End If
Set MyBarCode = Nothing         ' destroy the bar code object
End Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Have you determined whether there is a file by that name in that directory?
 
Upvote 0
Have you determined whether there is a file by that name in that directory?


I'd guess that it was there, shg4421, as two lines above, the code looks as if it might put it there (MyBarCode.SaveBarCode).
 
Upvote 0
If you're looking for an easy way to generate barcodes why not just use a barcode font?

I use #39: http://www.idautomation.com/fonts/

If you select the range where you want barcodes, set the font to the barcode you want, enter the barcode string text and voila, you have a barcode.

HTH,
 
Upvote 0
I understand why you need code instead of just a font, due to the encoding issues. The code you provided above worked perfectly for me using the Demo version of the TAL Barcode control...except for the word "Demo" in the middle of the code :)
I am using Excel 2007 on Windows XP. Perhaps it's a version difference?
Sorry I couldn't reproduce the problem...that's usually the first step to solving it!
Cindy
 
Upvote 0

Forum statistics

Threads
1,216,084
Messages
6,128,722
Members
449,465
Latest member
TAKLAM

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top