QR code to load a static barcode control on a worksheet

kelly mort

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

Some videos you may like

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
1,751
Office Version
2016
Platform
Windows
Bump.

Still needs help with this please
 

kelly mort

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

Watch MrExcel Video

Forum statistics

Threads
1,102,066
Messages
5,484,502
Members
407,442
Latest member
infinia

This Week's Hot Topics

  • Finding issue in If elseif else with For each Loop
    Finding issue in If elseif else with For each Loop I have tried this below code but i'm getting in Y column filled with W005. Colud you please...
  • MsgBox Error
    Hi Guys, I have the below error show up when i try and run my macro in File1 but works fine if i copy and paste the same code into file2. [ATTACH...
  • CELL FORMAT - IF CONDITION
    My Cell Format is [B]""0.00" Cr". [/B]But in the cell, it is showing 123.00 for editing. (123 is entry figure). (Data imported from other...
  • Show numbers nearly the same
    Is this possible. I have a number that can change very time eg 0.00001234 Then I have a lot of numbers 0.0000001, 0.0000002, 0.00000004...
  • Please i need your help to create formula
    I need a formula in cell B8 to do this >>if b1=1 then multiply ( cell b8) by 10% ,if b1=2 multiply by 20%,if=3 multiply by 30%. Thank you in...
  • Got error while adding column and filter
    Got error while adding column and filter In column Z has some like "Success" and "Error". I want to add column in AA if the Z cell value is...
Top