我正在尝试制作一个4x 6标签,上面有7个code-39条形码,但似乎我的VBA代码覆盖了每个条形码。数据是从Excel文件的单元格B2 - B8中提取的,现在我只能打印2个。此时它只打印B3中的数据,而不是B2和B3。
我也想弄清楚如何让文字显示在A2 - A8栏的每个条形码上方,但还没有到这一步。我试着查找如何做到这一点,但还没有找到很多关于VBA到Word应用程序的信息。以下是我的代码,我真的很感激任何帮助,因为我没有任何VBA的经验。
Sub Button2_Click()
Dim WdApp As Object, WdDoc As Object, StrCd As String, StrCl As String
With ActiveSheet
StrCd = Chr(34) & .Range("B2").Value & Chr(34)
StrCl = Chr(34) & .Range("B3").Value & Chr(34)
End With
Set WdApp = CreateObject("Word.Application"): Set WdDoc = WdApp.Documents.Add
With WdDoc
.PageSetup.PageWidth = 288: .PageSetup.PageHeight = 432: .PageSetup.RightMargin = 36: .PageSetup.LeftMargin = 36
.Fields.Add .Range, -1, "DISPLAYBARCODE " & StrCd & " CODE39 \d \t", False
.Fields.Add .Range, -1, "DISPLAYBARCODE " & StrCl & " CODE39 \d \t", False
With .Range
With .ParagraphFormat
.LineSpacingRule = 0 'wdLineSpaceSingle
.SpaceBefore = 0
.SpaceAfter = 1
End With
.Copy
End With
ActiveSheet.PasteSpecial Format:="Picture (Enhanced Metafile)", Link:=False, DisplayAsIcon:=False
.Close False
End With
Set WdDoc = Nothing: WdApp.Quit: Set WdApp = Nothing
End Sub
1条答案
按热度按时间epggiuax1#
您可以尝试以下操作: