常见问题:TBarCode Office Excel 加载项
如何在单元格更改后自动更新条码?
如何在单元格更改后自动更新条码?
对于 EMF 条码,条码会在打印和保存文档时更新。如果您需要在特定单元格或区域发生更改时立即更新条码,可以使用宏来实现:
- 在加载项选项中启用“保存时刷新条码”。
- 将以下代码添加到您的 Excel 表格中(ALT-F11),并将其保存为启用宏的工作簿。
Private Sub Worksheet_Change(ByVal Target As Range)
' specify the range, which will trigger the auto-save here
If (InRange(Target, Range("A1:A10"))) Then
Application.DisplayStatusBar = True
Application.ActiveWorkbook.Save
Application.StatusBar = "Auto-Save done!"
End If
End SubFunction InRange(Range1 As Range, Range2 As Range) As Boolean
InRange = Not (Application.Intersect(Range1, Range2) Is Nothing)
End Function
该宏会保存文档,从而触发条码更新。
Excel 在设计模式下会禁用宏(或事件驱动的宏)。由于 TBarCode 面板在编辑对象时会切换到设计模式,因此您需要先关闭 TBarCode 面板才能启用该宏。