QR code to load a static barcode control on a worksheet

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
1,573
I have this code here, to create qr code. It's doing well getting the code.

But I am thinking of having a pre-created barcode control, where I only run the code to load the control instead of creating new one each time.

Maybe, the sheet change event will do the job. But since this object is new to me, I have no idea what to code down.

I have the feeling someone have the solution.
Code:
Sub setQR()
    Dim xObjOLE As OLEObject
    On Error Resume Next
   
    Application.ScreenUpdating = False
    Set xObjOLE = ActiveSheet.OLEObjects.Add("BARCODE.BarCodeCtrl.1")
    xObjOLE.Object.Style = 11
    xObjOLE.Object.Value = [A1].Text
    
    Application.ScreenUpdating = True
End Sub
 

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
1,573
So from series of trials, this is how the code is looking like.

Code:
[COLOR=#0A0101][FONT=monospace][COLOR=#006699][B]Sub[/B][/COLOR] [COLOR=#000000]setQR()[/COLOR][/FONT][/COLOR]
[COLOR=#0A0101][FONT=monospace][COLOR=#008200]'Updated by Extendoffice 2018/8/22[/COLOR][/FONT][/COLOR]
[COLOR=#0A0101][FONT=monospace][COLOR=#006699][B]Dim[/B][/COLOR] [COLOR=#000000]xSRg [/COLOR][COLOR=#006699][B]As[/B][/COLOR] [COLOR=#000000]Range[/COLOR][/FONT][/COLOR]
[COLOR=#0A0101][FONT=monospace][COLOR=#006699][B]Dim[/B][/COLOR] [COLOR=#000000]xRRg [/COLOR][COLOR=#006699][B]As[/B][/COLOR] [COLOR=#000000]Range[/COLOR][/FONT][/COLOR]
[COLOR=#0A0101][FONT=monospace][COLOR=#006699][B]Dim[/B][/COLOR] [COLOR=#000000]xObjOLE [/COLOR][COLOR=#006699][B]As[/B][/COLOR] [COLOR=#000000]OLEObject[/COLOR][/FONT][/COLOR]
[COLOR=#0A0101][FONT=monospace][COLOR=#006699][B]On[/B][/COLOR] [COLOR=#006699][B]Error[/B][/COLOR] [COLOR=#006699][B]Resume[/B][/COLOR] [COLOR=#006699][B]Next[/B][/COLOR][/FONT][/COLOR]
[COLOR=#0A0101][FONT=monospace][COLOR=#006699][B]Set[/B][/COLOR] [COLOR=#000000]xSRg = [A1][/COLOR][/FONT][/COLOR]
[COLOR=#0A0101][FONT=monospace][COLOR=#006699][B]Set[/B][/COLOR] [COLOR=#000000]xRRg = [F8][/COLOR][/FONT][/COLOR]

[COLOR=#0A0101][FONT=monospace][COLOR=#000000]Application.ScreenUpdating = [/COLOR][COLOR=#006699][B]False[/B][/COLOR][/FONT][/COLOR]
[COLOR=#0A0101][FONT=monospace][COLOR=#006699][B]Set[/B][/COLOR] [COLOR=#000000]xObjOLE = ActiveSheet.OLEObjects.Add(​[/COLOR][COLOR=#0000FF]"BARCODE.BarCodeCtrl.1"​[/COLOR][COLOR=#000000])[/COLOR][/FONT][/COLOR]
[COLOR=#0A0101][FONT=monospace][COLOR=#000000]xObjOLE.[/COLOR][COLOR=#006699][B]Object[/B][/COLOR][COLOR=#000000].Style = 11[/COLOR][/FONT][/COLOR]
[COLOR=#0A0101][FONT=monospace][COLOR=#000000]xObjOLE.​[/COLOR][COLOR=#006699][B]Object​[/B][/COLOR][COLOR=#000000].Value = xSRg.Text[/COLOR][/FONT][/COLOR]
[COLOR=#0A0101][FONT=monospace][COLOR=#DD0055]    '[/COLOR][COLOR=#000000]ActiveSheet.Shapes.Item(xObjOLE.Name).Copy[/COLOR][/FONT][/COLOR]
[COLOR=#0A0101][FONT=monospace][COLOR=#DD0055]    '[/COLOR][COLOR=#000000]ActiveSheet.Paste xRRg[/COLOR][/FONT][/COLOR]
[COLOR=#0A0101][FONT=monospace][COLOR=#DD0055]    '[/COLOR][COLOR=#000000]xObjOLE.Delete[/COLOR][/FONT][/COLOR]
[COLOR=#0A0101][FONT=monospace][COLOR=#000000]Application.ScreenUpdating = [/COLOR][COLOR=#006699][B]True[/B][/COLOR][/FONT][/COLOR]
[COLOR=#0A0101][FONT=monospace][COLOR=#006699][B]End[/B][/COLOR] [COLOR=#006699][B]Sub[/B][/COLOR][/FONT][/COLOR]
After thinking and studying the code for a while, I observed that I can use the code just as it was, by creating new object each time.
So what I will do is to later delete it.

So I am placing the object in cell F8 , one of the coolest tweak I have done. Lol.

Now, my only issue, is to be able to resize the shape.

I tried
Code:
[COLOR=#000000][FONT=monospace]xObjOLE.[/FONT][/COLOR][COLOR=#006699][FONT=monospace][B]Object[/B][/FONT][/COLOR][COLOR=#000000][FONT=monospace].Height =50
[/FONT][/COLOR][COLOR=#000000][FONT=monospace]xObjOLE.[/FONT][/COLOR][COLOR=#006699][FONT=monospace][B]Object[/B][/FONT][/COLOR][COLOR=#000000][FONT=monospace].Width =50[/FONT][/COLOR]
And I was told object does not support that property.

Please, help
 

Forum statistics

Threads
1,077,662
Messages
5,335,564
Members
399,025
Latest member
alce

Some videos you may like

This Week's Hot Topics

Top