FAQ TBarCode OCX
Al Imprimir mediante Excel VBA: el Código de Barras No Se Actualiza
Al Imprimir mediante Excel VBA: el Código de Barras No Se Actualiza
Cambia el contenido de las celdas vinculadas o el control de código de barras, y luego imprime directamente desde VBA. Pero ve que los controles de código de barras aún contienen los valores antiguos. La razón es que Excel no envía un comando de redibujado a los controles ActiveX antes de imprimir (si se hace desde VBA). Esto es un error de Excel.
Existe una solución alternativa para forzar un redibujado de los objetos: debe dirigirse a cada control ActiveX de código de barras mediante programación en VBA y cambiar su tamaño antes de imprimir. Entonces Excel lo redibujará.
'redraw a single barcode object by addressing it through its instance name Dim origValue origValue = TBarCode101.Width TBarCode101.Width = origValue + 1 TBarCode101.Width = origValue
' redraw all ActiveX Controls on the current sheet
Sub UpdateOLEControls()
Dim myShape As shape
Dim counter As Integer
Dim origWidth As Single
For counter = 1 To ActiveSheet.Shapes.Count
Set myShape = ActiveSheet.Shapes(counter)
If (myShape.Type = msoOLEControlObject) Then
' resize => force redraw
origWidth = myShape.Width
myShape.Width = origWidth + 1
myShape.Width = origWidth
End If
Next counter
End Sub