我正在尝试生成条形码并将它们保存到电子表格中

I'm attempting to generate barcodes and save them to a spreadsheet

我正在尝试想出一种更好的方法来执行以下代码。它按原样工作,但由于 windows 剪贴板内存泄漏的问题,它不可靠且速度不是很快。如果可能的话,我想将从 word.application 复制的图像直接分配到一个数组中,或者至少能够绕过已经尝试了好几天的剪贴板。

    Dim ShapeName As String
    Const BarcodeWidth As Integer = 175
    Dim ws As Worksheet, WdApp
    Set ws = ActiveSheet
    Set WdApp = CreateObject("Word.Application")

Do Until ActiveSheet.Cells(RowLoc, 1) = "End of File"

    ShapeName = ActiveSheet.Cells(RowLoc, 1)
    
    With WdApp.Documents.Add
        .PageSetup.RightMargin = .PageSetup.PageWidth - .PageSetup.LeftMargin - BarcodeWidth
        .Fields.Add(Range:=.Range, Type:=-1, Text:="DISPLAYBARCODE " & ShapeName & " CODE128 \d \t", PreserveFormatting:=False).Copy 
    End With

    Sheets("Barcode").Cells(RowLoc, 5).Select                                                'selects the location where the bar code will be pasted
    ws.PasteSpecial Format:="Picture (Enhanced Metafile)", Link:=False, DisplayAsIcon:=False 'Pastes the bar code at the current selection
    RowLoc = RowLoc + 1
    Selection.name = ShapeName
    Application.CutCopyMode = False
Loop
    WdApp.Quit SaveChanges:=False
    Set WdApp = Nothing
End Sub

我从来没有找到在 excel 中存储图像的方法,但是我发现实现我想要的最好方法是创建代码,以我需要的格式准备数据,然后邮件合并结果到模板中创建我想要的运输标签。