QR code to load a static barcode control on a worksheet

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
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
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
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
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top