如何在Excel工作表中生成条形码

只是一个简短的问题,如何在Excel工作表中生成条形码? 条码文本已经在单元格中指定。

(无意批量生成条码,否则可以在MS Word中完成)

select条码文本的写入范围:

在这里输入图像说明

然后运行以下脚本:

Sub INSERT_BARCODE() Const BarcodeWidth As Integer = 156 Dim ws As Worksheet, WdApp Set ws = ActiveSheet Set WdApp = CreateObject("Word.Application") With WdApp.Documents.Add .PageSetup.RightMargin = .PageSetup.PageWidth - .PageSetup.LeftMargin - BarcodeWidth .Fields.Add(Range:=.Range, Type:=-1, Text:="DISPLAYBARCODE " & CStr(Selection.Value) & " CODE39 \d \t", PreserveFormatting:=False).Copy End With ws.PasteSpecial Format:="Picture (Enhanced Metafile)", Link:=False, DisplayAsIcon:=False WdApp.Quit SaveChanges:=False Set WdApp = Nothing End Sub 

在这里输入图像说明

注意:

BR〜

这大大超出了你需要的东西,但是你可以根据需要把它们拉出来。

 Sub Call_Barcode_Service() Dim strResource As String Dim strSize As String Dim iHgt As Integer Dim iWth As Integer Dim iGap As Integer Dim PictureGrab As String Dim lngLastRow As Long strSize = UCase(InputBox("How Big?", "Small, Medium or Large?", "L")) Select Case strSize Case Is = "S" iWth = 150 iHgt = 45 iGap = 3 Case Is = "M" iWth = 150 iHgt = 60 iGap = 4 Case Is = "L" iWth = 240 iHgt = 75 iGap = 5 Case Else iWth = 250 iHgt = 75 iGap = 5 End Select Set sel = Selection.SpecialCells(xlTextValues) Set news = Worksheets.Add() news.Name = "Barcodes" Set op = news.Range("A1") For Each acc In sel strResource = acc.Value PictureGrab = "http://www.barcodesinc.com/generator/image.php?code=" & strResource & "&style=197&type=C128B&width=" & iWth & "&height=" & iHgt & "&xres=1&font=1" Set sh = ActiveSheet.Shapes.AddShape(msoShapeRectangle, op.Left, op.Top, iWth, iHgt) With sh .Name = strResource .Line.Visible = False .Fill.UserPicture PictureGrab End With Set op = op.Offset(iGap + 1, 0).Range("A1") Next Range("G1").Select End Sub