Hi,
I have downloaded an excel VBA barcode generating code but is having issues on this line
This the full code. Kindly advise as to what needs to be done here.
Thanks!
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